|
96 | 96 | (let [line-offset (get args "line_offset" 0) |
97 | 97 | limit (get args "limit" (get-in config [:toolCall :readFile :maxLines])) |
98 | 98 | sub-read (or line-offset limit)] |
99 | | - (format "Reading file %s %s" |
| 99 | + (format "Reading %s %s" |
100 | 100 | (fs/file-name (fs/file path)) |
101 | 101 | (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)))))) |
107 | 106 | "Reading file")) |
108 | 107 |
|
109 | 108 | (defn ^:private write-file [arguments _] |
|
117 | 116 | :content old-content}]))) |
118 | 117 |
|
119 | 118 | (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" |
122 | 121 | "Creating file")) |
123 | 122 |
|
| 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 | + |
124 | 140 | (defn ^:private run-ripgrep [path pattern include output-mode] |
125 | 141 | (let [mode-flags (case output-mode |
126 | 142 | "content" ["-n" "--no-heading"] |
|
253 | 269 | (defn grep-summary [{:keys [args]}] |
254 | 270 | (if-let [pattern (get args "pattern")] |
255 | 271 | (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)) |
258 | 274 | "Searching for files")) |
259 | 275 |
|
260 | 276 | (defn ^:private handle-file-change-result |
|
342 | 358 | ["destination" (complement fs/exists?) "Path $destination already exists"]]) |
343 | 359 | (let [source (get arguments "source") |
344 | 360 | destination (get arguments "destination") |
345 | | - source-content (slurp source)] |
| 361 | + directory? (fs/directory? source) |
| 362 | + source-content (when-not directory? (slurp source))] |
346 | 363 | (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"))) |
352 | 380 |
|
353 | 381 | (def definitions |
354 | 382 | {"directory_tree" |
|
361 | 389 | :required ["path"]} |
362 | 390 | :handler #'directory-tree |
363 | 391 | :require-approval-fn (tools.util/require-approval-when-outside-workspace ["path"]) |
364 | | - :summary-fn (constantly "Listing file tree")} |
| 392 | + :summary-fn #'directory-tree-summary} |
365 | 393 | "read_file" |
366 | 394 | {:description (tools.util/read-tool-description "read_file") |
367 | 395 | :parameters {:type "object" |
|
400 | 428 | :required ["path" "original_content" "new_content"]} |
401 | 429 | :handler #'edit-file |
402 | 430 | :require-approval-fn (tools.util/require-approval-when-outside-workspace ["path"]) |
403 | | - :summary-fn (constantly "Editing file")} |
| 431 | + :summary-fn #'edit-file-summary} |
404 | 432 | "preview_file_change" |
405 | 433 | {:description (tools.util/read-tool-description "preview_file_change") |
406 | 434 | :parameters {:type "object" |
|
426 | 454 | :required ["source" "destination"]} |
427 | 455 | :handler #'move-file |
428 | 456 | :require-approval-fn (tools.util/require-approval-when-outside-workspace ["source" "destination"]) |
429 | | - :summary-fn (constantly "Moving file")} |
| 457 | + :summary-fn #'move-file-summary} |
430 | 458 | "grep" |
431 | 459 | {:description (tools.util/read-tool-description "grep") |
432 | 460 | :parameters {:type "object" |
|
0 commit comments