Skip to content

Commit f40651b

Browse files
committed
Improve summary of tool calls
1 parent 4083359 commit f40651b

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

CHANGELOG.md

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

33
## Unreleased
44

5+
- Improve summary of filesystem and shell functions making cleaner.
6+
- Fix `move_file` not working for renaming.
7+
58
## 0.121.1
69

710
- Fix remote connection for tailscale + docs.

src/eca/config.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
:ask {}
169169
:deny {}}
170170
:readFile {:maxLines 2000}
171-
:shellCommand {:summaryMaxLength 25}
171+
:shellCommand {:summaryMaxLength 35}
172172
:outputTruncation {:lines 2000 :sizeKb 50}}
173173
:variantsByModel {".*sonnet[-._]4[-._]6|opus[-._]4[-._][56]" {:variants anthropic-variants}
174174
".*gpt[-._]5(?:[-._](?:2|4)(?!\\d)|[-._]3[-._]codex)" {:variants openai-variants

src/eca/features/tools/filesystem.clj

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@
9696
(let [line-offset (get args "line_offset" 0)
9797
limit (get args "limit" (get-in config [:toolCall :readFile :maxLines]))
9898
sub-read (or line-offset limit)]
99-
(format "Reading file %s %s"
99+
(format "Reading %s %s"
100100
(fs/file-name (fs/file path))
101101
(str
102-
(when sub-read
103-
(format "(%s-%s)"
104-
line-offset
105-
(+ line-offset limit)))
106-
)))
102+
(when sub-read
103+
(format "(%s-%s)"
104+
line-offset
105+
(+ line-offset limit))))))
107106
"Reading file"))
108107

109108
(defn ^:private write-file [arguments _]
@@ -117,10 +116,27 @@
117116
:content old-content}])))
118117

119118
(defn ^:private write-file-summary [{:keys [args]}]
120-
(if-let [path (get args "path")]
121-
(str "Creating file " (fs/file-name (fs/file path)))
119+
(if (get args "path")
120+
"Creating"
122121
"Creating file"))
123122

123+
(defn ^:private edit-file-summary [{:keys [args]}]
124+
(if (get args "path")
125+
"Editing"
126+
"Editing file"))
127+
128+
(defn ^:private directory-tree-summary [{:keys [args db]}]
129+
(if-let [path (get args "path")]
130+
(let [root (path->root-filename db path)
131+
display-path (if root
132+
(let [rel (str (fs/relativize (fs/path root) (fs/path path)))]
133+
(if (= rel "")
134+
(fs/file-name (fs/file root))
135+
rel))
136+
path)]
137+
(str "Listing tree: " display-path))
138+
"Listing tree"))
139+
124140
(defn ^:private run-ripgrep [path pattern include output-mode]
125141
(let [mode-flags (case output-mode
126142
"content" ["-n" "--no-heading"]
@@ -253,8 +269,8 @@
253269
(defn grep-summary [{:keys [args]}]
254270
(if-let [pattern (get args "pattern")]
255271
(if (> (count pattern) 22)
256-
(format "Searching for '%s...'" (subs pattern 0 22))
257-
(format "Searching for '%s'" pattern))
272+
(format "Searching: %s..." (subs pattern 0 22))
273+
(format "Searching: %s" pattern))
258274
"Searching for files"))
259275

260276
(defn ^:private handle-file-change-result
@@ -342,13 +358,25 @@
342358
["destination" (complement fs/exists?) "Path $destination already exists"]])
343359
(let [source (get arguments "source")
344360
destination (get arguments "destination")
345-
source-content (slurp source)]
361+
directory? (fs/directory? source)
362+
source-content (when-not directory? (slurp source))]
346363
(fs/move source destination {:replace-existing false})
347-
(assoc (tools.util/single-text-content (format "Successfully moved %s to %s" source destination))
348-
:rollback-changes [{:path destination
349-
:content nil}
350-
{:path source
351-
:content source-content}]))))
364+
(cond-> (tools.util/single-text-content (format "Successfully moved %s to %s" source destination))
365+
(not directory?) (assoc :rollback-changes [{:path destination
366+
:content nil}
367+
{:path source
368+
:content source-content}])))))
369+
370+
(defn ^:private move-file-summary [{:keys [args]}]
371+
(let [source (get args "source")
372+
destination (get args "destination")]
373+
(if (and source destination)
374+
(let [source-parent (some-> source fs/path fs/parent str)
375+
dest-parent (some-> destination fs/path fs/parent str)]
376+
(if (= source-parent dest-parent)
377+
(str "Renaming " (fs/file-name (fs/file source)))
378+
(str "Moving " (fs/file-name (fs/file source)))))
379+
"Moving file")))
352380

353381
(def definitions
354382
{"directory_tree"
@@ -361,7 +389,7 @@
361389
:required ["path"]}
362390
:handler #'directory-tree
363391
:require-approval-fn (tools.util/require-approval-when-outside-workspace ["path"])
364-
:summary-fn (constantly "Listing file tree")}
392+
:summary-fn #'directory-tree-summary}
365393
"read_file"
366394
{:description (tools.util/read-tool-description "read_file")
367395
:parameters {:type "object"
@@ -400,7 +428,7 @@
400428
:required ["path" "original_content" "new_content"]}
401429
:handler #'edit-file
402430
:require-approval-fn (tools.util/require-approval-when-outside-workspace ["path"])
403-
:summary-fn (constantly "Editing file")}
431+
:summary-fn #'edit-file-summary}
404432
"preview_file_change"
405433
{:description (tools.util/read-tool-description "preview_file_change")
406434
:parameters {:type "object"
@@ -426,7 +454,7 @@
426454
:required ["source" "destination"]}
427455
:handler #'move-file
428456
:require-approval-fn (tools.util/require-approval-when-outside-workspace ["source" "destination"])
429-
:summary-fn (constantly "Moving file")}
457+
:summary-fn #'move-file-summary}
430458
"grep"
431459
{:description (tools.util/read-tool-description "grep")
432460
:parameters {:type "object"

src/eca/features/tools/shell.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@
139139
(if-let [command (some-> (get args "command")
140140
(strip-workspace-cd-prefix workspace-folders))]
141141
(if (> (count command) max-length)
142-
(format "Running '%s...'" (subs command 0 max-length))
143-
(format "Running '%s'" command))
144-
"Running shell command")))
142+
(format "$ %s..." (subs command 0 max-length))
143+
(format "$ %s" command))
144+
"Preparing shell command")))
145145

146146
(def definitions
147147
{"shell_command"

0 commit comments

Comments
 (0)