fix(permission): use absolute paths for external file permission matching#18628
Open
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Open
fix(permission): use absolute paths for external file permission matching#18628kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
Conversation
…hing Edit, write, and apply_patch tools were sending relative paths (e.g. ../../.config/file.txt) in permission check patterns, while config rules expand to absolute paths (e.g. /Users/x/.config/**). Wildcard.match() never matched, so edit/write rules for external files silently fell through to the default "allow" action. For files outside the worktree, use absolute paths in permission patterns so they correctly match expanded config rules. Internal files keep relative paths for backward compatibility. Closes anomalyco#18441
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #18441
Type of change
What does this PR do?
The
edit,write, andapply_patchtools send permission check patterns as relative paths from the worktree (e.g.../../.config/opencode/file.txt). Meanwhile, user-defined permission rules in config are expanded to absolute paths (e.g./Users/x/.config/opencode/**after~/expansion inPermission.fromConfig()).Wildcard.match()compares these two different formats and never matches, so edit/write rules for external files silently fall through to the default{ permission: "*", pattern: "*", action: "allow" }rule — bypassing any user-specified"ask"or"deny"restrictions.The fix checks whether the target file is inside the worktree via
Instance.containsPath():"src/**")"/Users/x/.config/**")This is consistent with how
assertExternalDirectory()already sends absolute glob patterns for theexternal_directorypermission check.How did you verify your code works?
bun run typecheckpasses (all 13 packages)/Users/x/.config/opencode/settings.jsonnow correctly matches a config rule{ "edit": { "~/.config/opencode/**": "ask" } }(expanded to/Users/x/.config/opencode/**)Screenshots / recordings
N/A
Checklist