|
9 | 9 | When `:config-file` from cli option is passed, it uses that instead of searching default locations." |
10 | 10 | (:require |
11 | 11 | [babashka.fs :as fs] |
12 | | - [borkdude.dynaload :refer [dynaload]] |
13 | 12 | [camel-snake-kebab.core :as csk] |
14 | 13 | [cheshire.core :as json] |
15 | 14 | [cheshire.factory :as json.factory] |
16 | 15 | [clojure.core.memoize :as memoize] |
17 | 16 | [clojure.java.io :as io] |
18 | 17 | [clojure.string :as string] |
19 | 18 | [clojure.walk :as walk] |
| 19 | + [eca.features.agents :as agents] |
| 20 | + [eca.interpolation :as interpolation] |
20 | 21 | [eca.logger :as logger] |
21 | 22 | [eca.messenger :as messenger] |
22 | | - [eca.secrets :as secrets] |
23 | 23 | [eca.shared :as shared :refer [multi-str]]) |
24 | 24 | (:import |
25 | 25 | [java.io File])) |
26 | 26 |
|
27 | 27 | (set! *warn-on-reflection* true) |
28 | 28 |
|
29 | | -(def ^:private all-md-agents (dynaload 'eca.features.agents/all-md-agents)) |
30 | | - |
31 | 29 | (def ^:private logger-tag "[CONFIG]") |
32 | 30 |
|
33 | 31 | (def ^:dynamic *env-var-config-error* false) |
|
174 | 172 | :autoCompactPercentage 75 |
175 | 173 | :env "prod"}) |
176 | 174 |
|
177 | | -(defn replace-dynamic-strings |
178 | | - "Given a string and a current working directory, look for patterns replacing its content: |
179 | | - - `${env:SOME-ENV:default-value}`: Replace with a env falling back to a optional default value |
180 | | - - `${file:/some/path}`: Replace with a file content checking from cwd if relative |
181 | | - - `${classpath:path/to/file}`: Replace with a file content found checking classpath |
182 | | - - `${netrc:api.provider.com}`: Replace with the content from Unix net RC [credential files](https://eca.dev/config/models/#credential-file-authentication)" |
183 | | - [s cwd config] |
184 | | - (some-> s |
185 | | - (string/replace #"\$\{env:([^:}]+)(?::([^}]*))?\}" |
186 | | - (fn [[_match env-var default-value]] |
187 | | - (or (get-env env-var) default-value ""))) |
188 | | - (string/replace #"\$\{file:([^}]+)\}" |
189 | | - (fn [[_match file-path]] |
190 | | - (try |
191 | | - (let [file-path (fs/expand-home file-path)] |
192 | | - (slurp (str (if (fs/absolute? file-path) |
193 | | - file-path |
194 | | - (if cwd |
195 | | - (fs/path cwd file-path) |
196 | | - (fs/path file-path)))))) |
197 | | - (catch Exception _ |
198 | | - (logger/warn logger-tag "File not found when parsing string:" s) |
199 | | - "")))) |
200 | | - (string/replace #"\$\{classpath:([^}]+)\}" |
201 | | - (fn [[_match resource-path]] |
202 | | - (try |
203 | | - (slurp (io/resource resource-path)) |
204 | | - (catch Exception e |
205 | | - (logger/warn logger-tag "Error reading classpath resource:" (.getMessage e)) |
206 | | - "")))) |
207 | | - (string/replace #"\$\{netrc:([^}]+)\}" |
208 | | - (fn [[_match key-rc]] |
209 | | - (try |
210 | | - (or (secrets/get-credential key-rc (get config "netrcFile")) "") |
211 | | - (catch Exception e |
212 | | - (logger/warn logger-tag "Error reading netrc credential:" (.getMessage e)) |
213 | | - "")))))) |
214 | | - |
215 | 175 | (defn ^:private parse-dynamic-string-values |
216 | 176 | "walk through config parsing dynamic string contents if value is a string." |
217 | 177 | [config cwd] |
218 | 178 | (walk/postwalk |
219 | 179 | (fn [x] |
220 | 180 | (if (string? x) |
221 | | - (replace-dynamic-strings x cwd config) |
| 181 | + (interpolation/replace-dynamic-strings x cwd config) |
222 | 182 | x)) |
223 | 183 | config)) |
224 | 184 |
|
|
455 | 415 | ;; Merge markdown-defined agents (lowest priority — JSON config agents win) |
456 | 416 | (as-> config |
457 | 417 | (let [md-agent-configs (when-not pure-config? |
458 | | - (all-md-agents (:workspace-folders db)))] |
| 418 | + ;; TODO how to avoid this dependency? |
| 419 | + (agents/all-md-agents (:workspace-folders db)))] |
459 | 420 | (if (seq md-agent-configs) |
460 | 421 | (update config :agent (fn [existing] |
461 | 422 | (merge md-agent-configs existing))) |
|
0 commit comments