kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

docs: correct permission rule precedence

Open LHMQ878 opened this issue 4 months ago • 2 comments

Related Issue

Resolve #1901

Problem

See linked issue. The permission section of the configuration docs describes [[permission.rules]] as "matched in order — the first matching rule takes effect", but matching is class-first, not position-first.

The practical cost is silent: the natural "allowlist plus catch-all deny" pattern looks like a working allowlist and behaves as a blanket denial. Anyone who writes that config and only tests the cases they expect to be denied will conclude it works.

What changed

Docs only, English and Chinese.

Corrected the precedence description. Matching is now documented as class-first: all deny rules are consulted, then all ask, then all allow, and file order only decides within one class. This matches both engines:

  • v1 — packages/agent-core/src/agent/permission/policies/index.ts, where UserConfiguredDeny / UserConfiguredAsk / UserConfiguredAllow sit in that fixed order under the header comment "Permission policies run in order; the first non-undefined result wins".
  • v2 — packages/agent-core-v2/src/agent/permissionPolicy/permissionPolicyService.ts, same ordering, with evaluate returning on the first defined result.

Within a class, firstMatchingRule in policies/user-configured-rule.ts filters by decision before scanning, so "first matching rule" does still hold there — the docs now say exactly where it holds.

Added a warning for the catch-all trap, with the config that does not work and what to write instead.

One correction worth flagging, because my first draft got it wrong: I initially suggested making the catch-all an ask instead of a deny. That is also broken — ask outranks allow by the same mechanism, so a catch-all ask suppresses a narrow allow just as a deny does. The advice in the final text is therefore to write no catch-all at all: an unmatched call already reaches the confirmation prompt via FallbackAskPermissionPolicy, unless the tool is in the DEFAULT_APPROVE_TOOLS set (Read, Grep, …), which the text notes.

Verification

Behaviour was checked against the real code rather than read off it — a throwaway vitest probe drove evaluateUserConfiguredRule through the same class order the policy chain uses (probe not included in the diff, this is a docs-only change):

Config Call Result
allow Bash(git status*) written first, deny Bash second git status deny — position ignored
same, with ask Bash as the catch-all git status ask — so ask is not a fix
narrow allow only, no catch-all git status / rm -rf tmpdir approve / falls through to ask
two deny rules, broad first git status first rule's reason — order does hold within a class

Also confirmed Read and Grep are in DEFAULT_APPROVE_TOOLS before naming them as examples.

pnpm lint (oxlint) passes, and vitepress build renders both pages with the new container as class="warning custom-block" and no literal ::: leaking into the HTML.

Checklist

  • [x] I have read the CONTRIBUTING document.
  • [x] I have linked a related issue, or explained the problem above.
  • [x] I have added tests that prove my feature works. — n/a, docs-only; the probe used to verify the described behaviour is summarised above.
  • [x] Ran gen-changesets skill, or this PR needs no changeset. — docs-only, no changeset per CONTRIBUTING.
  • [x] Ran gen-docs skill, or this PR needs no doc update. — this PR is the doc update; English and Chinese kept in sync.

LHMQ878 avatar Jul 27 '26 11:07 LHMQ878

⚠️ No Changeset found

Latest commit: 8ff414368e73b84a7c9e5fc8c58b2a32da111a85

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 27 '26 11:07 changeset-bot[bot]

Both review points addressed in 8ff4143.

1. Chinese callout title — changed ::: warning to ::: warning 注意 per docs/AGENTS.md; the file already used that form at the existing callout, so this was an inconsistency I introduced.

2. The no-catch-all guidance was mode-dependent — you're right, and it turned out to matter more than "add a caveat". I traced the chain in packages/agent-core-v2/src/agent/permissionPolicy/permissionPolicyService.ts:

# policy
2 user-configured-deny
3 auto-mode-approve
5 user-configured-ask
6 user-configured-allow
9 yolo-mode-approve
10 default-tool-approve
12 fallback-ask

fallback-ask is last, so the two autonomous modes preempt it — but not identically, and the difference is worth documenting:

  • yolo approves at position 9, i.e. after the user's deny and ask rules. It only bypasses the fallback prompt.
  • auto approves at position 3, ahead of both user-configured-ask and user-configured-allow. Under auto, only deny rules have any effect whatsoever — an ask rule is silently dead.

So the guidance is now scoped to manual (the default), with both modes spelled out separately and an explicit note that any call you want stopped needs a deny rule. Same edit in the en and zh files.

Happy to trim this back to a one-line caveat if you'd rather keep the permission section short — the auto-drops-ask behaviour might belong in the default_permission_mode row instead.

LHMQ878 avatar Jul 28 '26 01:07 LHMQ878