From d41c49abf36ce0e0eaf1e58bceedae7e8458447d Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 15 Apr 2026 12:32:42 +0100 Subject: 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. --- kaagum/tools/base.scm | 24 ++++++++++++------------ 1 file 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. -- cgit 1.4.1