Skip to content

Commit

Permalink
fix(llm_tools): fix permission checking to use relative path (#1473)
Browse files Browse the repository at this point in the history
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 <me@yuchanns.xyz>
  • Loading branch information
yuchanns authored Mar 3, 2025
1 parent 6f13034 commit c6d5527
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lua/avante/llm_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>
Expand Down

0 comments on commit c6d5527

Please sign in to comment.