fix(tool): use relative path for read permission patterns#23051
fix(tool): use relative path for read permission patterns#23051kagura-agent wants to merge 1 commit intoanomalyco:devfrom
Conversation
The read tool was passing absolute file paths to permission evaluation while user-configured permission rules use relative paths. This caused exact path deny rules (e.g., 'src/main/.../File.java': 'deny') to never match, since Wildcard.match compared an absolute path against a relative pattern. Other tools (write, edit, apply_patch) already use path.relative(Instance.worktree, filepath) for permission patterns. This change makes the read tool consistent. Fixes anomalyco#23048 Related: anomalyco#6892
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found the following potentially related PRs:
These PRs likely have overlapping concerns with path resolution and permission pattern matching for the |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #23048
Related: #6892
Type of change
What does this PR do?
The
readtool passes absolute file paths to permission evaluation, but user-configured deny rules use relative paths. So exact path rules like"src/.../File.java": "deny"never match —Wildcard.matchcompares the absolute path against the relative pattern and fails.Wildcards like
*File.javastill work because*matches the absolute prefix too.The fix: use
path.relative(Instance.worktree, filepath)for the permission pattern, same aswrite.ts(line 46) andedit.ts(line 78) already do.Instance.worktreeis already imported and used inread.tsline 92 for the display title.One-line change, no new imports needed.
How did you verify your code works?
Verified by code inspection:
write.tsline 46:patterns: [path.relative(Instance.worktree, filepath)]✅edit.tsline 78:patterns: [path.relative(Instance.worktree, filePath)]✅read.tsline 108 (before):patterns: [filepath]— absolute path ❌read.tsline 108 (after):patterns: [path.relative(Instance.worktree, filepath)]✅All CI checks pass.
Screenshots / recordings
N/A — not a UI change.
Checklist