Skip to content

fix(opencode): Use standard resolve function to get proper filePaths for tools#18761

Open
OpeOginni wants to merge 29 commits into
anomalyco:devfrom
OpeOginni:fix/perms-system-file-path
Open

fix(opencode): Use standard resolve function to get proper filePaths for tools#18761
OpeOginni wants to merge 29 commits into
anomalyco:devfrom
OpeOginni:fix/perms-system-file-path

Conversation

@OpeOginni
Copy link
Copy Markdown
Contributor

@OpeOginni OpeOginni commented Mar 23, 2026

Issue for this PR

Closes #18762

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:issue contributor and removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@OpeOginni
Copy link
Copy Markdown
Contributor Author

When a project has no git worktree, Instance.worktree falls back to /. The tools were using that value to build the path passed into permission checks, so a file like:

/Users/me/project/.agents/file.txt

was being checked as:

Users/me/project/.agents/file.txt

instead of:

.agents/file.txt

That meant config rules like .agents/* or test/* would not match, even though the file was inside the allowed folder. If "*" was set to "deny", the operation was blocked.

This PR adds a small relative() helper that falls back to Instance.directory when the worktree is /, so non-git projects still use project-relative paths for permission checks.

It also adds regression tests for the affected tools to make sure permission checks continue receiving project-relative paths in non-git projects.

Reproduction

Use 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 .agents/ or test/, then ask the agent to read or edit it.

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 .agents/* and test/* match correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with Tool Permissions in Non Git Projects

1 participant