Skip to content

fix(opencode): match absolute permission rules against worktree-relative patterns - #48194

Closed
czk wants to merge 3 commits into
anomalyco:devfrom
czk:fix/permission-absolute-rules
Closed

czk wants to merge 3 commits into
anomalyco:devfrom
czk:fix/permission-absolute-rules

Conversation

@czk

@czk czk commented Sep 9, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #48193

Type of change

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

What does this PR do?

Tools send the permission matcher worktree-relative patterns (path.relative(worktree, filepath)), so a config rule written as an absolute path ({"edit": {"/czk/**": "allow"}}) never competes — inside the worktree the pattern is relative (facts/me.md), outside it is traversal (../../czk/...), without git context it is de-rooted (czk/...). Related: #40149 fixes this at the five tool call sites; this PR fixes it inside the matcher instead, so every caller benefits without changing what patterns look like.

evaluateCandidates() evaluates the original pattern as before, plus an absolutized candidate (path.resolve(worktree, pattern)) — but only against rules whose own pattern starts with /. Relative-semantic rules like "*" keep their original meaning and cannot allow a path outside the worktree through the absolutized candidate. Across candidates: deny > allow > ask.

How did you verify your code works?

  • 7 new tests in test/permission/absolute-rules.test.ts: the three pattern forms, deny precedence over "*", no leak of "*" via the absolutized candidate, unchanged behavior for relative-only rulesets
  • bun test test/permission/: 92/92 pass
  • bun test test/acp/ test/cli/: 501 tests, only a pre-existing help-text snapshot failure that also fails on clean dev (verified by stashing this change)

Screenshots / recordings

Not a UI change.

Checklist

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

…ive patterns

Permission patterns produced by tools are worktree-relative
(path.relative(worktree, filePath)), so config rules written as
absolute paths never match: inside the worktree paths arrive as
relative ("facts/me.md"), outside as traversal ("../../czk/..."),
and without a git context as de-rooted ("czk/...").

Add evaluateCandidates(): alongside the original pattern, evaluate an
absolutized candidate (path.resolve(worktree, pattern)), but only
against rules whose pattern is absolute (leading "/"). Absolute
rules work as users expect, while relative-semantic rules like "*"
keep their original meaning and cannot allow paths outside the
worktree. Deny > allow > ask across candidates.

7 new tests in test/permission/absolute-rules.test.ts; permission
suite passes (92), acp/cli suites unchanged.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found a potentially related PR:

#40149 - fix(opencode): match absolute permission patterns outside the worktree

This PR appears to address a similar issue with absolute permission pattern matching. While PR #48194 focuses on matching absolute permission rules against worktree-relative patterns, PR #40149 seems to handle a related aspect of absolute permission pattern matching behavior.

However, given that PR #48194 is specifically fixing issue #48193 with a new test suite and a different implementation approach (evaluateCandidates() logic), these likely represent two distinct phases of permission pattern matching improvements rather than exact duplicates.

No other open PRs appear to be duplicates of the current PR #48194.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

Absolute-path permission rules never match (tool patterns are worktree-relative)

1 participant