Skip to content

fix(permissions): warn when all-tools rules are reordered for last-match targets - #3897

Merged
dyoshikawa merged 3 commits into
mainfrom
resolve-issue-3876-warn-all-tools-reorder
Nov 19, 2026
Merged

dyoshikawa merged 3 commits into
mainfrom
resolve-issue-3876-warn-all-tools-reorder

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

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:

  • Warning: restateAllToolsRestrictionsLast now logs a warning whenever reordering the * key changes the authored order, in the same spirit as mergePatternRules, 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: the JSDoc and 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.ts is regenerated.
  • Shared helper: sortRulesByActionPriority in single-action-collapse.ts replaces both the triple loop in last-match-restate.ts and the inline sort in mergePatternRules. It builds the result with Object.fromEntries, so a __proto__ pattern is no longer dropped.
  • Tests: unit tests cover the warning (and no warning when the order is already right) and the __proto__ pattern. Generate-path tests check the emitted order with Object.entries for OpenCode V2, OpenCode V1 and Kilo, and check that an opencode.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

dyoshikawa and others added 2 commits November 20, 2026 00:21
…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
@dyoshikawa
dyoshikawa merged commit 470fd15 into main Nov 19, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3876-warn-all-tools-reorder branch November 19, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn and document when all-tools rules are reordered for last-match targets (follow-up to #3866)

1 participant