Repository navigation
fix(permissions): warn when all-tools rules are reordered for last-match targets - #3897
Merged
Merged
Conversation
…tch targets OpenCode, OpenCode V1, MiMo Code and Kilo order the all-tools `*` key's patterns allow, ask, deny so the strictest matching rule wins. That silently disabled an allow carve-out under a broader ask or deny in that key. Log a warning whenever the order changes, pointing at `<target>.permission["*"]` for an exact order, and document the behaviour. Extract `sortRulesByActionPriority` and share it with OpenCode's `mergePatternRules`; it also keeps a `__proto__` pattern that the previous plain-object assignment dropped. Add generate-path tests for OpenCode V2, OpenCode V1 and Kilo. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…overridden The warning advised setting `<target>.permission["*"]`, yet it still fired when that override was already set, since the reorder runs on the shared block before the override is applied. Pass whether the override defines `*` and stay quiet then. Also say the reorder "may" disable a looser carve-out, since not every reordered input has one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…rn-all-tools-reorder # Conflicts: # src/generated/docs-content.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3876
Summary
Since #3866, OpenCode (V2 and V1), MiMo Code and Kilo order the all-tools
*key's patterns allow → ask → deny so the strictest matching rule wins. That is the correct canonical semantics, but it silently disabled a common carve-out such as{"*": {"*": "ask", "src/**": "allow"}}. This PR handles the follow-ups from the review:restateAllToolsRestrictionsLastnow logs a warning whenever reordering the*key changes the authored order, in the same spirit asmergePatternRules, and points at<target>.permission["*"]for an exact order. The function now takes an object argument ({ sharedPermission, toolTarget, logger }) so OpenCode/OpenCode V1/MiMo Code and Kilo pass their target name and logger.docs/reference/file-formats.md(the all-tools*paragraph and the OpenCode section) now say the*key is ordered allow, ask, deny;src/generated/docs-content.tsis regenerated.sortRulesByActionPriorityinsingle-action-collapse.tsreplaces both the triple loop inlast-match-restate.tsand the inline sort inmergePatternRules. It builds the result withObject.fromEntries, so a__proto__pattern is no longer dropped.__proto__pattern. Generate-path tests check the emitted order withObject.entriesfor OpenCode V2, OpenCode V1 and Kilo, and check that anopencode.permission["*"]override keeps its exact order.The output order itself does not change from
main. The only new behavior is the warning.Item 5 of the issue (integer-like keys sorting first in JS objects) is still part of #3822 and is not handled here.
Test plan
pnpm cicheck(fmt, lint, typecheck, 17065 tests, content checks) passes.🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4