Skip to content

Commit 271dfd9

Browse files
committed
Fix local config read
1 parent 1839b95 commit 271dfd9

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fix ollama servers discovery
6+
- Fix `.eca/config.json` read from workspace root
67

78
## 0.0.2
89

src/eca/config.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
(:require
99
[camel-snake-kebab.core :as csk]
1010
[cheshire.core :as json]
11+
[clojure.core.memoize :as memoize]
1112
[clojure.java.io :as io]
12-
[clojure.string :as string]))
13+
[clojure.string :as string]
14+
[eca.shared :as shared]))
1315

1416
(def ^:private initial-config
1517
{:openai-api-key nil
1618
:anthropic-api-key nil
1719
:rules []
20+
:mcp-servers []
1821
:ollama {:host "http://localhost"
1922
:port 11434}
2023
:chat {:welcome-message "Welcome to ECA! What you have in mind?\n\n"}
2124
:index {:ignore-files [{:type :gitignore}]}})
2225

26+
(def ttl-cache-config-ms 5000)
27+
2328
(defn ^:private safe-read-json-string [raw-string]
2429
(try
2530
(json/parse-string raw-string (fn [key]
@@ -33,12 +38,18 @@
3338

3439
(def ^:private config-from-envvar (memoize config-from-envvar*))
3540

36-
(defn ^:private config-from-file* []
37-
(let [config-file (io/file ".eca" "config.json")]
38-
(when (.exists config-file)
39-
(safe-read-json-string (slurp config-file)))))
41+
(defn ^:private config-from-file* [roots]
42+
(reduce
43+
(fn [final-config {:keys [uri]}]
44+
(merge
45+
final-config
46+
(let [config-file (io/file (shared/uri->filename uri) ".eca" "config.json")]
47+
(when (.exists config-file)
48+
(safe-read-json-string (slurp config-file))))))
49+
{}
50+
roots))
4051

41-
(def ^:private config-from-local-file (memoize config-from-file*))
52+
(def ^:private config-from-local-file (memoize/ttl config-from-file* :ttl/threshold ttl-cache-config-ms))
4253

4354
(defn ^:private deep-merge [& maps]
4455
(apply merge-with (fn [& args]
@@ -54,7 +65,7 @@
5465

5566
(def ollama-model-prefix "ollama:")
5667

57-
(defn all []
68+
(defn all [db]
5869
(deep-merge initial-config
5970
(config-from-envvar)
60-
(config-from-local-file)))
71+
(config-from-local-file (:workspace-folders db))))

src/eca/features/chat.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
(defn query-context
146146
[{:keys [query contexts chat-id]}
147147
db*]
148-
(let [config (config/all)
148+
(let [config (config/all @db*)
149149
all-subfiles-and-dirs (into []
150150
(comp
151151
(map :uri)

src/eca/handlers.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
[eca.logger :as logger]))
88

99
(defn ^:private initialize-extra-models! [db*]
10-
(let [config (config/all)]
10+
(let [config (config/all @db*)]
1111
(when-let [ollama-models (seq (llm-api/extra-models config))]
1212
(swap! db* update :models concat (map #(str config/ollama-model-prefix (:model %)) ollama-models)))))
1313

1414
(defn initialize [{:keys [db*]} params]
1515
(logger/logging-task
1616
:eca/initialize
17-
(let [config (config/all)]
17+
(let [config (config/all @db*)]
1818
(swap! db* assoc
1919
:client-info (:client-info params)
2020
:workspace-folders (:workspace-folders params)
@@ -36,7 +36,7 @@
3636
(defn chat-prompt [{:keys [messenger db*]} params]
3737
(logger/logging-task
3838
:eca/chat-prompt
39-
(let [config (config/all)]
39+
(let [config (config/all @db*)]
4040
(f.chat/prompt params db* messenger config))))
4141

4242
(defn chat-query-context [{:keys [db*]} params]

0 commit comments

Comments
 (0)