Repository navigation
Conversation
Replace findLast() in evaluate() with a specificity-based algorithm: most specific pattern (longest literal prefix before first wildcard) wins over less specific patterns, regardless of insertion order. Fixes the problem where a broad deny like /home/m/* at the end of a ruleset silently overrides more specific allows like /home/m/Projects/tools/paper-making-system/* that appear earlier. - Add specificity() helper: counts literal chars before first * or ? - V1 evaluate() and disabled(): use specificity-based selection - V2 evaluate(): same change for the core permission system - Tests: update names and expectations to match new semantics
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
…te specificity tests - disabled() now considers pattern specificity (not just permission specificity), so specific patterns keep a tool visible even when a wildcard deny exists for the same permission - Fix 2 tests that weren't updated to specificity semantics: - next.test.ts: wildcard permission no longer overrides specific - permission-task.test.ts: disabled() with specific patterns is false - Add 10 direct evaluate() specificity tests for V2 in core
whollyDisabled() in tool/registry.ts had the same findLast bug — a specific allow like question.private was ignored when *: deny appeared later. Now uses the same action+resource specificity algorithm as evaluate(). Also rename remaining tests/comments that still referenced 'last matching rule' semantics to reflect specificity-based behavior.
Policy.evaluate() had the same specificity-blind bug as permission evaluate(): findLast picked the last matching statement regardless of specificity. Changed to the same action+resource specificity algorithm used in permission evaluate(). Add test for specific-before-wildcard ordering that would have failed with findLast.
|
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:
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. |
Issue for this PR
Closes #37935, #24335, #31854, #36765
Type of change
What does this PR do?
Replaces
findLast()in both V1 and V2 permissionevaluate()functions with a most-specific-pattern-wins algorithm. Thespecificity()helper counts literal characters before the first*or?wildcard. When two rules both match, the one with higher specificity wins; ties are broken by position (later wins).Before (broken): a broad deny like
$HOME/*→ deny at the end of a ruleset silently overrides a more specific allow like$HOME/utilities/*→ allow that appears earlier, becausefindLast()picks the last matching rule regardless of specificity.After (fixed): the more specific pattern wins.
$HOME/utilities(specificity 48) beats$HOME/*(specificity 8). Same for bash command patterns:rm(specificity 2) beats*(specificity 0).Also updates
disabled()to use the same specificity logic when determining whether a tool is completely hidden.How did you verify your code works?
packages/opencode/test/permission/next.test.tsandpackages/opencode/test/permission-task.test.tsto match the new specificity-based semanticsorigin/devbase with zero unrelated changesScreenshots / recordings
N/A (logic change, not UI)
Checklist