From c6d5527ea811bf8f99e3ebeacf3978f38d4c28a4 Mon Sep 17 00:00:00 2001 From: Hanchin Hsieh Date: Mon, 3 Mar 2025 18:02:59 +0800 Subject: [PATCH] fix(llm_tools): fix permission checking to use relative path (#1473) The has_permission_to_access function was incorrectly using absolute paths when checking against gitignore patterns. This could cause issues when the binary name matches the project root directory name, particularly in Go projects. Changes: - Extract relative path from absolute path by removing project root prefix - Use relative path for gitignore pattern matching - Add comments explaining the path handling logic Signed-off-by: Hanchin Hsieh --- lua/avante/llm_tools.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/avante/llm_tools.lua b/lua/avante/llm_tools.lua index 9458396..5380460 100644 --- a/lua/avante/llm_tools.lua +++ b/lua/avante/llm_tools.lua @@ -30,7 +30,12 @@ local function has_permission_to_access(abs_path) if abs_path:sub(1, #project_root) ~= project_root then return false end local gitignore_path = project_root .. "/.gitignore" local gitignore_patterns, gitignore_negate_patterns = Utils.parse_gitignore(gitignore_path) - return not Utils.is_ignored(abs_path, gitignore_patterns, gitignore_negate_patterns) + -- The checker should only take care of the path inside the project root + -- Specifically, it should not check the project root itself + -- Otherwise if the binary is named the same as the project root (such as Go binary), any paths + -- insde the project root will be ignored + local rel_path = Path:new(abs_path):make_relative(project_root) + return not Utils.is_ignored(rel_path, gitignore_patterns, gitignore_negate_patterns) end ---@type AvanteLLMToolFunc<{ rel_path: string, max_depth?: integer }>