|
35 | 35 |
|
36 | 36 | (def custom-config-file-path* (atom nil)) |
37 | 37 |
|
38 | | -(def initial-config |
| 38 | +(defn get-env [env] (System/getenv env)) |
| 39 | +(defn get-property [property] (System/getProperty property)) |
| 40 | + |
| 41 | +(def ^:private initial-config* |
39 | 42 | {:providers {"openai" {:api "openai-responses" |
40 | 43 | :url "https://api.openai.com" |
41 | 44 | :key nil |
|
84 | 87 | "ollama" {:url "http://localhost:11434" |
85 | 88 | :urlEnv "OLLAMA_API_URL"}} |
86 | 89 | :defaultBehavior "agent" |
87 | | - :behavior {"agent" {:systemPromptFile "prompts/agent_behavior.md" |
| 90 | + :behavior {"agent" {:systemPrompt "${classpath:prompts/agent_behavior.md}" |
88 | 91 | :disabledTools ["preview_file_change"]} |
89 | | - "plan" {:systemPromptFile "prompts/plan_behavior.md" |
| 92 | + "plan" {:systemPrompt "${classpath:prompts/plan_behavior.md}" |
90 | 93 | :disabledTools ["edit_file" "write_file" "move_file"] |
91 | 94 | :toolCall {:approval {:allow {"eca__shell_command" |
92 | 95 | {:argsMatchers {"command" ["pwd"]}} |
|
139 | 142 | :repoMap {:maxTotalEntries 800 |
140 | 143 | :maxEntriesPerDir 50}} |
141 | 144 | :completion {:model "openai/gpt-4.1" |
142 | | - :systemPromptFile "prompts/inline_completion.md"} |
143 | | - :rewrite {:systemPromptFile "prompts/rewrite.md"} |
| 145 | + :systemPrompt "${classpath:prompts/inline_completion.md}"} |
| 146 | + :rewrite {:systemPrompt "${classpath:prompts/rewrite.md}"} |
144 | 147 | :netrcFile nil |
145 | 148 | :env "prod"}) |
146 | 149 |
|
147 | | -(def ^:private fallback-behavior "agent") |
148 | | - |
149 | | -(defn validate-behavior-name |
150 | | - "Validates if a behavior exists in config. Returns the behavior if valid, |
151 | | - or the fallback behavior if not." |
152 | | - [behavior config] |
153 | | - (if (contains? (:behavior config) behavior) |
154 | | - behavior |
155 | | - (do (logger/warn logger-tag (format "Unknown behavior '%s' specified, falling back to '%s'" |
156 | | - behavior fallback-behavior)) |
157 | | - fallback-behavior))) |
158 | | - |
159 | | -(defn get-env [env] (System/getenv env)) |
160 | | -(defn get-property [property] (System/getProperty property)) |
161 | | - |
162 | 150 | (defn ^:private parse-dynamic-string |
163 | 151 | "Given a string and a current working directory, look for patterns replacing its content: |
164 | 152 | - `${env:SOME-ENV}`: Replace with a env |
165 | | - - `${file:/some/path}`: Replace with a file content checking from cwd if relative" |
| 153 | + - `${file:/some/path}`: Replace with a file content checking from cwd if relative |
| 154 | + - `${classpath:path/to/file}`: Replace with a file content found checking classpath" |
166 | 155 | [s cwd] |
167 | 156 | (some-> s |
168 | 157 | (string/replace #"\$\{env:([^}]+)\}" |
|
173 | 162 | (try |
174 | 163 | (slurp (str (if (fs/absolute? file-path) |
175 | 164 | file-path |
176 | | - (fs/path cwd file-path)))) |
| 165 | + (if cwd |
| 166 | + (fs/path cwd file-path) |
| 167 | + (fs/path file-path))))) |
177 | 168 | (catch Exception _ |
178 | 169 | (logger/warn logger-tag "File not found when parsing string:" s) |
| 170 | + "")))) |
| 171 | + (string/replace #"\$\{classpath:([^}]+)\}" |
| 172 | + (fn [[_match resource-path]] |
| 173 | + (try |
| 174 | + (slurp (io/resource resource-path)) |
| 175 | + (catch Exception e |
| 176 | + (logger/warn logger-tag "Error reading classpath resource:" (.getMessage e)) |
179 | 177 | "")))))) |
180 | 178 |
|
181 | 179 | (defn ^:private parse-dynamic-string-values |
|
188 | 186 | x)) |
189 | 187 | config)) |
190 | 188 |
|
| 189 | +(def initial-config (memoize #(parse-dynamic-string-values initial-config* nil))) |
| 190 | + |
| 191 | +(def ^:private fallback-behavior "agent") |
| 192 | + |
| 193 | +(defn validate-behavior-name |
| 194 | + "Validates if a behavior exists in config. Returns the behavior if valid, |
| 195 | + or the fallback behavior if not." |
| 196 | + [behavior config] |
| 197 | + (if (contains? (:behavior config) behavior) |
| 198 | + behavior |
| 199 | + (do (logger/warn logger-tag (format "Unknown behavior '%s' specified, falling back to '%s'" |
| 200 | + behavior fallback-behavior)) |
| 201 | + fallback-behavior))) |
| 202 | + |
191 | 203 | (def ^:private ttl-cache-config-ms 5000) |
192 | 204 |
|
193 | 205 | (defn ^:private safe-read-json-string [raw-string config-dyn-var] |
|
341 | 353 | (defn all [db] |
342 | 354 | (let [initialization-config @initialization-config* |
343 | 355 | pure-config? (:pureConfig initialization-config)] |
344 | | - (deep-merge initial-config |
| 356 | + (deep-merge (initial-config) |
345 | 357 | (normalize-fields |
346 | 358 | eca-config-normalization-rules |
347 | 359 | (deep-merge initialization-config |
|
0 commit comments