From c72003b0b60eb4e622f07fb2c23fd5eb14874748 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Thu, 12 Mar 2026 13:38:15 -0600 Subject: [PATCH] fix: Implemented the path normalization fix for the oracle and explore agents --- assets/agents/explore/tools.sh | 26 ++++++++++++++++++++++---- assets/agents/oracle/tools.sh | 27 +++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/assets/agents/explore/tools.sh b/assets/agents/explore/tools.sh index 510d4f3..6fc9384 100755 --- a/assets/agents/explore/tools.sh +++ b/assets/agents/explore/tools.sh @@ -14,6 +14,21 @@ _project_dir() { (cd "${dir}" 2>/dev/null && pwd) || echo "${dir}" } +# Normalize a path to be relative to project root. +# Strips the project_dir prefix if the LLM passes an absolute path. +_normalize_path() { + local input_path="$1" + local project_dir + project_dir=$(_project_dir) + + if [[ "${input_path}" == /* ]]; then + input_path="${input_path#"${project_dir}"/}" + fi + + input_path="${input_path#./}" + echo "${input_path}" +} + # @cmd Get project structure and layout get_structure() { local project_dir @@ -78,6 +93,7 @@ search_content() { grep -v '/node_modules/' | \ grep -v '/.git/' | \ grep -v '/dist/' | \ + sed "s|^${project_dir}/||" | \ head -30) || true if [[ -n "${results}" ]]; then @@ -91,8 +107,9 @@ search_content() { # @option --path! Path to the file (relative to project root) # @option --lines Maximum lines to read (default: 200) read_file() { + local file_path # shellcheck disable=SC2154 - local file_path="${argc_path}" + file_path=$(_normalize_path "${argc_path}") local max_lines="${argc_lines:-200}" local project_dir project_dir=$(_project_dir) @@ -122,7 +139,8 @@ read_file() { # @cmd Find similar files to a given file (for pattern matching) # @option --path! Path to the reference file find_similar() { - local file_path="${argc_path}" + local file_path + file_path=$(_normalize_path "${argc_path}") local project_dir project_dir=$(_project_dir) @@ -138,7 +156,7 @@ find_similar() { ! -name "$(basename "${file_path}")" \ ! -name "*test*" \ ! -name "*spec*" \ - 2>/dev/null | head -5) + 2>/dev/null | sed "s|^${project_dir}/||" | head -5) if [[ -n "${results}" ]]; then echo "${results}" >> "$LLM_OUTPUT" @@ -147,7 +165,7 @@ find_similar() { ! -name "$(basename "${file_path}")" \ ! -name "*test*" \ -not -path '*/target/*' \ - 2>/dev/null | head -5) + 2>/dev/null | sed "s|^${project_dir}/||" | head -5) if [[ -n "${results}" ]]; then echo "${results}" >> "$LLM_OUTPUT" else diff --git a/assets/agents/oracle/tools.sh b/assets/agents/oracle/tools.sh index 6e9f4a2..4eb0a16 100755 --- a/assets/agents/oracle/tools.sh +++ b/assets/agents/oracle/tools.sh @@ -14,21 +14,38 @@ _project_dir() { (cd "${dir}" 2>/dev/null && pwd) || echo "${dir}" } +# Normalize a path to be relative to project root. +# Strips the project_dir prefix if the LLM passes an absolute path. +_normalize_path() { + local input_path="$1" + local project_dir + project_dir=$(_project_dir) + + if [[ "${input_path}" == /* ]]; then + input_path="${input_path#"${project_dir}"/}" + fi + + input_path="${input_path#./}" + echo "${input_path}" +} + # @cmd Read a file for analysis # @option --path! Path to the file (relative to project root) read_file() { local project_dir project_dir=$(_project_dir) + local file_path # shellcheck disable=SC2154 - local full_path="${project_dir}/${argc_path}" + file_path=$(_normalize_path "${argc_path}") + local full_path="${project_dir}/${file_path}" if [[ ! -f "${full_path}" ]]; then - error "File not found: ${argc_path}" >> "$LLM_OUTPUT" + error "File not found: ${file_path}" >> "$LLM_OUTPUT" return 1 fi { - info "Reading: ${argc_path}" + info "Reading: ${file_path}" echo "" cat "${full_path}" } >> "$LLM_OUTPUT" @@ -80,6 +97,7 @@ search_code() { grep -v '/target/' | \ grep -v '/node_modules/' | \ grep -v '/.git/' | \ + sed "s|^${project_dir}/||" | \ head -30) || true if [[ -n "${results}" ]]; then @@ -113,7 +131,8 @@ analyze_with_command() { # @cmd List directory contents # @option --path Path to list (default: project root) list_directory() { - local dir_path="${argc_path:-.}" + local dir_path + dir_path=$(_normalize_path "${argc_path:-.}") local project_dir project_dir=$(_project_dir) local full_path="${project_dir}/${dir_path}"