fix(permission): port upstream case-insensitive file permission matching on macOS (anomalyco/opencode#64626)
Issue for this PR
Closes #1841
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Ports upstream https://github.com/anomalyco/opencode/pull/64626.
User-visible failure: macOS file systems ignore case by default, but the fork matched file permission rules with case. A rule like edit: { ".opencode/*": "ask" }, read: { "*.env": "ask" }, an external_directory deny or a sensitive_write guard (.git/*) did not fire when the agent used a different spelling such as .OPENCODE/plugins/x.ts, Secrets.ENV or .GIT/hooks/pre-commit. The file system still opened the protected file, so the write or read happened with no prompt.
Change: in PermissionEvaluate.matchPattern (packages/opencode/src/permission/evaluate.ts), on darwin the input and pattern are lowercased for the file path permissions read, edit, external_directory and sensitive_write. Upstream added an ignoreCase flag to Wildcard.match; the fork's Wildcard already has its own match/matchPath split (Windows already matches without case), so the fork applies the change at the one place where rules are matched. Command rules (bash, etc.) and Linux behaviour do not change. Wrapped in altimate_change start — upstream_fix: markers.
How did you verify your code works?
- New
packages/opencode/test/permission/case.test.ts(4 tests): on macOS each file permission matches a different-case path,bashrules keep case, Linux keeps case. 2 of the tests fail without the fix. bun test test/permission test/permission-task.test.ts test/permission-yolo.test.ts test/tool/search-read-permissions.test.ts: 225 pass, 0 fail.tsgo --noEmitinpackages/opencode: pass (run with--singleThreaded; the multi-threaded run was killed for memory on the 8 GB VM).bun run script/upstream/analyze.ts --markers --base origin/main --strict: ok.bun script/check-tracker-leaks.ts: ok.
Cost side effects
None. Only changes how permission rules are compared; no model calls, queries or cloud resources.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Summary by cubic
Fixes macOS permission matching so case differences no longer bypass file path guards. Because macOS volumes ignore case, a path like .OPENCODE/x opened a file protected by the rule .opencode/*, letting writes, reads, and external directory access proceed without a prompt. read, edit, external_directory, and sensitive_write rules are now matched case-insensitively on macOS only; command rules and Linux behavior are unchanged.
Ports the upstream fix in anomalyco/opencode#64626.
- Windows already matched file paths without case; the fork centers the change at the single rule-matching point in
evaluate.ts. - Adds
case.test.tswith 4 tests covering macOS file rules, macOS command rules, and Linux behavior. - No cost side effects: only rule comparison changes, no model calls or queries.