about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-04-15 12:32:42 +0100
committerArun Isaac2026-04-15 12:36:37 +0100
commitd41c49abf36ce0e0eaf1e58bceedae7e8458447d (patch)
tree27e75e02d95edc3344da9834be1db0dc4a693133
parent75f7692f10d7d05aaffe48cea5348086f34932da (diff)
downloadkaagum-d41c49abf36ce0e0eaf1e58bceedae7e8458447d.tar.gz
kaagum-d41c49abf36ce0e0eaf1e58bceedae7e8458447d.tar.lz
kaagum-d41c49abf36ce0e0eaf1e58bceedae7e8458447d.zip
Handle regular files in files-recursively.
The LLM often tries to search a single file by passing in a single
file to the #:files-root parameter of the search tool. This crashes
files-recursively because it is expecting a directory. We now support
this in files-recursively.
-rw-r--r--kaagum/tools/base.scm24
1 files changed, 12 insertions, 12 deletions
diff --git a/kaagum/tools/base.scm b/kaagum/tools/base.scm
index 87a4688..51043b6 100644
--- a/kaagum/tools/base.scm
+++ b/kaagum/tools/base.scm
@@ -55,21 +55,21 @@ valid regular expression."
              (exit #f)))
     (make-regexp pattern)))
 
-(define (files-recursively directory pattern)
-  "Return a list of all files recursively down @var{directory} whose basename
-matches regular expression @var{pattern}. Hidden directories are not traversed."
+(define (files-recursively path pattern)
+  "Return a list of all files recursively down @var{path} whose basename matches
+regular expression @var{pattern}. Hidden directories are not traversed.
+@var{path} may be a directory or any other file type. If @var{path} is not a
+directory, return a singleton list with @var{path} alone."
   (cond
-   ((not (file-exists? directory))
+   ((not (file-exists? path))
     (format (current-output-port)
-            "Error: Directory ~a does not exist~%"
-            directory)
+            "Error: Path ~a does not exist~%"
+            path)
     (exit #f))
-   ((not (eq? (stat:type (stat directory))
+   ;; Return regular files (and other non-directory files) in a singleton list.
+   ((not (eq? (stat:type (stat path))
               'directory))
-    (format (current-output-port)
-            "Error: ~a is not a directory~%"
-            directory)
-    (exit #f))
+    (list path))
    (else
     (let ((pattern-rx (make-regexp* pattern)))
       (file-system-fold (lambda (path stat result)
@@ -91,7 +91,7 @@ matches regular expression @var{pattern}. Hidden directories are not traversed."
                                   (strerror errno))
                           result)
                         (list)
-                        (canonicalize-path directory))))))
+                        (canonicalize-path path))))))
 
 (define %read
   (tool #:description "Read whole text file, or optionally a subset of its lines.