Skip to content

Commit 804a588

Browse files
committed
Fix custom tools output to return stderr when tool error.
Fixes #219
1 parent 8996fa0 commit 804a588

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
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+
- Fix custom tools output to return stderr when tool error. #219
6+
57
## 0.82.0
68

79
- Support nested folder for rules and commands. #220

src/eca/features/tools/custom.clj

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@
3636
err (some-> (:err result) string/trim)
3737
out (some-> (:out result) string/trim)]
3838
(logger/debug logger-tag "custom tool executed:" result)
39-
(if (zero? exit)
40-
(tools.util/single-text-content out)
41-
{:error true
42-
:contents (remove nil?
43-
(concat [{:type :text
44-
:text (str "Exit code " exit)}]
45-
(when-not (string/blank? err)
46-
[{:type :text
47-
:text (str "Stderr:\n" err)}])
48-
(when-not (string/blank? out)
49-
[{:type :text
50-
:text (str "Stdout:\n" out)}])))}))))
39+
{:error (not= 0 exit)
40+
:contents (remove nil?
41+
(concat [(when (not= 0 exit)
42+
{:type :text
43+
:text (str "Exit code " exit)})]
44+
(when-not (string/blank? err)
45+
[{:type :text
46+
:text (str "Stderr:\n" err)}])
47+
(when-not (string/blank? out)
48+
[{:type :text
49+
:text (str "Stdout:\n" out)}])))})))
5150

5251
(defn ^:private custom-tool->tool-def
5352
"Transforms a single custom tool from the config map into a full tool definition."

test/eca/features/tools/custom_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
custom-tool-def (get custom-defs "file-search")]
2222
(is (some? custom-tool-def) "The custom tool should be loaded.")
2323
(let [result ((:handler custom-tool-def) {"directory" "/tmp" "pattern" "*.clj"} {})]
24-
(is (= {:contents [{:text "mocked-output", :type :text}], :error false} result) "The tool should return the mocked shell output.")))))))
24+
(is (= {:contents [{:text "Stdout:\nmocked-output", :type :text}], :error false} result) "The tool should return the mocked shell output.")))))))
2525

2626
(testing "when multiple tools are configured"
2727
(let [mock-custom-tools {"git-status"
@@ -42,8 +42,8 @@
4242
echo-handler (get-in custom-defs ["echo-message" :handler])]
4343
(is (some? git-status-handler) "Git status tool should be loaded.")
4444
(is (some? echo-handler) "Echo message tool should be loaded.")
45-
(is (= {:contents [{:text "On branch main", :type :text}], :error false} (git-status-handler {} {})))
46-
(is (= {:contents [{:text "Hello World", :type :text}], :error false} (echo-handler {"message" "Hello World"} {})))))))
45+
(is (= {:contents [{:text "Stdout:\nOn branch main", :type :text}], :error false} (git-status-handler {} {})))
46+
(is (= {:contents [{:text "Stdout:\nHello World", :type :text}], :error false} (echo-handler {"message" "Hello World"} {})))))))
4747

4848
(testing "when the custom tools config is empty or missing"
4949
(testing "with an empty map"

0 commit comments

Comments
 (0)