Skip to content

Commit 5ca2b3a

Browse files
committed
Improve tool call result marking as error when not expected output.
1 parent e4cac50 commit 5ca2b3a

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
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+
- Improve tool call result marking as error when not expected output.
6+
57
## 0.12.4
68

79
- Add chat command type.

src/eca/features/chat.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@
383383
(defn query-commands
384384
[{:keys [query chat-id]}
385385
db*]
386-
(let [mcp-prompts (->> (f.mcp/all-prompts @db*)
386+
(let [query (string/lower-case query)
387+
mcp-prompts (->> (f.mcp/all-prompts @db*)
387388
(mapv #(-> %
388389
(assoc :name (str (:server %) ":" (:name %))
389390
:type :mcpPrompt)
@@ -396,8 +397,8 @@
396397
eca-commands)
397398
commands (if (string/blank? query)
398399
commands
399-
(filter #(or (string/includes? (:name %) query)
400-
(string/includes? (:description %) query))
400+
(filter #(or (string/includes? (string/lower-case (:name %)) query)
401+
(string/includes? (string/lower-case (:description %)) query))
401402
commands))]
402403
{:chat-id chat-id
403404
:commands commands}))

src/eca/features/tools/filesystem.clj

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
pattern)))
6868
[]
6969
(:workspace-folders db))]
70-
(tools.util/single-text-content (if (seq paths)
71-
(string/join "\n" paths)
72-
"No matches found")))))
70+
(if (seq paths)
71+
(tools.util/single-text-content (string/join "\n" paths))
72+
(tools.util/single-text-content "No matches found" :error)))))
7373

7474
(defn ^:private run-ripgrep [path pattern include]
7575
(let [cmd (cond-> ["rg" "--files-with-matches" "--no-heading"]
@@ -159,9 +159,9 @@
159159
(run-java-grep path pattern include))
160160
(take max-results))]
161161
;; TODO sort by modification time.
162-
(tools.util/single-text-content (if (seq paths)
163-
(string/join "\n" paths)
164-
"No files found for given pattern")))))
162+
(if (seq paths)
163+
(tools.util/single-text-content (string/join "\n" paths))
164+
(tools.util/single-text-content "No files found for given pattern" :error)))))
165165

166166
(defn ^:private replace-in-file [arguments {:keys [db]}]
167167
(or (tools.util/invalid-arguments arguments (concat (path-validations db)
@@ -171,14 +171,13 @@
171171
new-content (get arguments "new_content")
172172
all? (boolean (get arguments "all_occurrences"))
173173
content (slurp path)]
174-
(tools.util/single-text-content
175-
(if (string/includes? content original-content)
176-
(let [content (if all?
177-
(string/replace content original-content new-content)
178-
(string/replace-first content original-content new-content))]
179-
(spit path content)
180-
(format "Successfully replaced content in %s." path))
181-
(format "Original content not found in %s" path))))))
174+
(if (string/includes? content original-content)
175+
(let [content (if all?
176+
(string/replace content original-content new-content)
177+
(string/replace-first content original-content new-content))]
178+
(spit path content)
179+
(tools.util/single-text-content (format "Successfully replaced content in %s." path)))
180+
(tools.util/single-text-content (format "Original content not found in %s" path) :error)))))
182181

183182
(defn ^:private move-file [arguments {:keys [db]}]
184183
(let [workspace-dirs (tools.util/workspace-roots-strs db)]

test/eca/features/tools/filesystem_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))
140140
(testing "no matches"
141141
(is (match?
142-
{:error false
142+
{:error true
143143
:contents [{:type :text
144144
:content "No matches found"}]}
145145
(with-redefs [fs/exists? (constantly true)
@@ -203,7 +203,7 @@
203203
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))
204204
(testing "no files found"
205205
(is (match?
206-
{:error false
206+
{:error true
207207
:contents [{:type :text
208208
:content "No files found for given pattern"}]}
209209
(with-redefs [fs/exists? (constantly true)
@@ -275,7 +275,7 @@
275275
{:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))
276276
(testing "original content not found"
277277
(is (match?
278-
{:error false
278+
{:error true
279279
:contents [{:type :text
280280
:content (format "Original content not found in %s" (h/file-path "/project/foo/my-file.txt"))}]}
281281
(with-redefs [fs/exists? (constantly true)

0 commit comments

Comments
 (0)