Skip to content

Commit dc770f3

Browse files
committed
Add login providers to doctor command
1 parent 5b93f51 commit dc770f3

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Add login providers to `/doctor`.
6+
57
## 0.36.1
68

79
- Improved the `eca_directory_tree` tool. #82

src/eca/features/commands.clj

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[eca.features.prompt :as f.prompt]
1111
[eca.features.tools.mcp :as f.mcp]
1212
[eca.llm-api :as llm-api]
13-
[eca.shared :as shared :refer [multi-str]]))
13+
[eca.shared :as shared :refer [multi-str update-some]]))
1414

1515
(set! *warn-on-reflection* true)
1616

@@ -105,19 +105,19 @@
105105
:type :native
106106
:description "Prompt sent to LLM as system instructions."
107107
:arguments []}]
108-
custom-commands (map (fn [custom]
109-
{:name (:name custom)
110-
:type :custom-prompt
111-
:description (:path custom)
112-
:arguments []})
113-
(custom-commands config (:workspace-folders db)))]
108+
custom-cmds (map (fn [custom]
109+
{:name (:name custom)
110+
:type :custom-prompt
111+
:description (:path custom)
112+
:arguments []})
113+
(custom-commands config (:workspace-folders db)))]
114114
(concat mcp-prompts
115115
eca-commands
116-
custom-commands)))
116+
custom-cmds)))
117117

118-
(defn ^:private get-custom-command [command args custom-commands]
118+
(defn ^:private get-custom-command [command args custom-cmds]
119119
(when-let [raw-content (:content (first (filter #(= command (:name %))
120-
custom-commands)))]
120+
custom-cmds)))]
121121
(let [raw-content (string/replace raw-content "$ARGS" (string/join " " args))]
122122
(reduce (fn [content [i arg]]
123123
(string/replace content (str "$ARG" (inc i)) arg))
@@ -130,6 +130,15 @@
130130
""
131131
(str "Default model: " model)
132132
""
133+
(str "Login providers: " (reduce
134+
(fn [s [provider auth]]
135+
(str s provider ": " (-> auth
136+
(update-some :verifier shared/obfuscate)
137+
(update-some :device-code shared/obfuscate)
138+
(update-some :access-token shared/obfuscate)
139+
(update-some :api-key shared/obfuscate)) "\n"))
140+
"\n"
141+
(:auth db)))
133142
(str "Relevant env vars: " (reduce (fn [s [key val]]
134143
(if (or (string/includes? key "KEY")
135144
(string/includes? key "API")
@@ -142,7 +151,7 @@
142151

143152
(defn handle-command! [command args {:keys [chat-id db* config full-model instructions]}]
144153
(let [db @db*
145-
custom-commands (custom-commands config (:workspace-folders db))]
154+
custom-cmds (custom-commands config (:workspace-folders db))]
146155
(case command
147156
"init" {:type :send-prompt
148157
:clear-history-after-finished? true
@@ -188,7 +197,7 @@
188197
:chats {chat-id [{:role "system" :content [{:type :text :text instructions}]}]}}
189198

190199
;; else check if a custom command
191-
(if-let [custom-command-prompt (get-custom-command command args custom-commands)]
200+
(if-let [custom-command-prompt (get-custom-command command args custom-cmds)]
192201
{:type :send-prompt
193202
:clear-history-after-finished? false
194203
:prompt custom-command-prompt}

src/eca/shared.clj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@
6060
"assoc-some expects even number of arguments after map/vector, found odd number")))
6161
ret))))
6262

63+
(defn update-some
64+
"Update if the value if not nil."
65+
([m k f]
66+
(if-let [v (get m k)]
67+
(assoc m k (f v))
68+
m))
69+
([m k f & args]
70+
(if-let [v (get m k)]
71+
(assoc m k (apply f v args))
72+
m)))
73+
6374
(defn multi-str [& strings] (string/join "\n" (remove nil? strings)))
6475

6576
(defn tokens->cost [input-tokens input-cache-creation-tokens input-cache-read-tokens output-tokens full-model db]
@@ -86,3 +97,17 @@
8697
(into {} (map f x))
8798
x))
8899
m)))
100+
101+
(defn obfuscate
102+
"Obfuscate all but first 3 and last 3 characters of a string, minimum 5 characters.
103+
If the string is 4 characters or less, obfuscate all characters.
104+
Replace the middle part with asterisks, but always at least 5 asterisks."
105+
[s]
106+
(when s
107+
(string/replace
108+
(if (<= (count s) 4)
109+
(apply str (repeat (count s) "*"))
110+
(str (subs s 0 3)
111+
(apply str (repeat (- (count s) 4) "*"))
112+
(subs s (- (count s) 3))))
113+
(string/join "" (repeat (- (count s) 4) "*")) "*****")))

0 commit comments

Comments
 (0)