fix(opencode): Use standard resolve function to get proper filePaths for tools#18761
fix(opencode): Use standard resolve function to get proper filePaths for tools#18761OpeOginni wants to merge 29 commits into
Conversation
…perly get file paths for permissions checks
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…r improved path handling
|
When a project has no git worktree, /Users/me/project/.agents/file.txtwas being checked as: Users/me/project/.agents/file.txtinstead of: .agents/file.txtThat meant config rules like This PR adds a small It also adds regression tests for the affected tools to make sure permission checks continue receiving project-relative paths in non-git projects. ReproductionUse a directory that is not git initialized and add this config: {
"$schema": "https://opencode.ai/config.json",
"agent": {
"build": {
"permission": {
"edit": {
"*": "deny",
".agents/*": "allow",
"test/*": "allow"
},
"read": {
"*": "deny",
".agents/*": "allow",
"test/*": "allow"
}
}
}
}
}Create a file inside Before this fix, the request could be denied because the path did not match the allowed pattern. After this fix, the path is checked relative to the project directory, so |
…r relative uitl function
Issue for this PR
Closes #18762
Type of change
What does this PR do?
When setting permissions for tools in a project that does not have git initialised, it gets the paths of files relative to its worktree, and for non-git projects the worktree is always
/, this breaks permissions as the filePath is not going to be what the Permission Rule expects.So this PR adds a check if the worktree is
/then go ahead to use the Instance directory. It also moves the resolve logic to its own file, so tools can all import from it, this makes the codebase a bit cleaner since all tools use the same logic.How did you verify your code works?
I tested with the case the user had an issue with, for both a non-git project and a git project, it works as it should.
Also added regression tests to the tools affected. The fixes makes them all pass
Screenshots / recordings
Checklist