From 2fe6704fbc167910f9167830e13b2fdd50bdebd9 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Tue, 14 Jul 2026 12:47:43 -0600 Subject: [PATCH] fix: fs tools now output better error handling to guide the model more effectively --- assets/functions/tools/fs_cat.sh | 12 ++++++++++-- assets/functions/tools/fs_glob.sh | 4 ++-- assets/functions/tools/fs_grep.sh | 4 ++-- assets/functions/tools/fs_ls.sh | 17 +++++++++++++++-- assets/functions/tools/fs_read.sh | 4 ++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/assets/functions/tools/fs_cat.sh b/assets/functions/tools/fs_cat.sh index 84713e0..e47a0ed 100755 --- a/assets/functions/tools/fs_cat.sh +++ b/assets/functions/tools/fs_cat.sh @@ -10,5 +10,13 @@ set -e main() { # shellcheck disable=SC2154 - cat "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such file or path: $argc_path" >> "$LLM_OUTPUT" -} \ No newline at end of file + local path="$argc_path" + + # An empty result is shown to the model as the opaque literal "DONE"; emit a note instead. + if [[ -f "$path" && ! -s "$path" ]]; then + echo "(empty file: $path)" >> "$LLM_OUTPUT" + return 0 + fi + + cat "$path" >> "$LLM_OUTPUT" 2>&1 || echo "No such file or path: $path" >> "$LLM_OUTPUT" +} diff --git a/assets/functions/tools/fs_glob.sh b/assets/functions/tools/fs_glob.sh index 05e4972..8271300 100644 --- a/assets/functions/tools/fs_glob.sh +++ b/assets/functions/tools/fs_glob.sh @@ -17,8 +17,8 @@ main() { local search_path="${argc_path:-.}" if [[ ! -d "$search_path" ]]; then - echo "Error: directory not found: $search_path" >> "$LLM_OUTPUT" - return 1 + echo "Error: directory not found: $search_path" >&2 + exit 1 fi local results diff --git a/assets/functions/tools/fs_grep.sh b/assets/functions/tools/fs_grep.sh index dc37216..2110a67 100644 --- a/assets/functions/tools/fs_grep.sh +++ b/assets/functions/tools/fs_grep.sh @@ -21,8 +21,8 @@ main() { local include_filter="${argc_include:-}" if [[ ! -e "$search_path" ]]; then - echo "Error: path not found: $search_path" >> "$LLM_OUTPUT" - return 1 + echo "Error: path not found: $search_path" >&2 + exit 1 fi local grep_args=(-nH --color=never) diff --git a/assets/functions/tools/fs_ls.sh b/assets/functions/tools/fs_ls.sh index 65f0e12..31779a1 100755 --- a/assets/functions/tools/fs_ls.sh +++ b/assets/functions/tools/fs_ls.sh @@ -9,5 +9,18 @@ set -e main() { # shellcheck disable=SC2154 - ls -1 "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such path: $argc_path" >> "$LLM_OUTPUT" -} \ No newline at end of file + local path="$argc_path" + local output + + if ! output=$(ls -1 "$path" 2>&1); then + echo "$output" >> "$LLM_OUTPUT" + return 0 + fi + + # An empty result is shown to the model as the opaque literal "DONE"; emit a note instead. + if [[ -z "$output" ]]; then + echo "(empty directory: $path)" >> "$LLM_OUTPUT" + else + echo "$output" >> "$LLM_OUTPUT" + fi +} diff --git a/assets/functions/tools/fs_read.sh b/assets/functions/tools/fs_read.sh index 9b5ffe1..ef08086 100644 --- a/assets/functions/tools/fs_read.sh +++ b/assets/functions/tools/fs_read.sh @@ -23,8 +23,8 @@ main() { local limit="${argc_limit:-2000}" if [[ ! -e "$target" ]]; then - echo "Error: path not found: $target" >> "$LLM_OUTPUT" - return 1 + echo "Error: path not found: $target" >&2 + exit 1 fi if [[ -d "$target" ]]; then