feat(grokcli): import the verbose [permission] rules form - #2642
Merged
Conversation
Grok's settings reference documents two permission forms under [permission]:
the compact allow/deny/ask arrays of Claude-style entries and the verbose
rules = [{ action, tool, pattern }] tables. The adapter parsed only the
arrays, so a config written entirely in the verbose form imported to empty
canonical permissions and fell back to the coarse [ui] permission_mode.
toRulesyncPermissions now also walks [[permission.rules]]. The entries are
TOML tables rather than entry strings, so the tool field is resolved through
a case-insensitive view of the same tool table (the reference writes it
lowercase; the array entries are capitalized). Rules from both forms merge
into one map with an explicit deny > ask > allow ranking, and a non-empty
rules array counts as fine-grained rules present so the coarse fallback is
not taken.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The settings reference restricts the verbose rule's tool field to any | bash | edit | read | grep | mcp | webfetch, so MCP is spelled 'mcp' there rather than the compact form's 'MCPTool'. Only the compact spelling was matched, which dropped every documented MCP rule on import. Both spellings are now accepted. Also guard the tool lookup with Object.hasOwn so a tool named after an Object.prototype member cannot resolve to a bogus category, reuse PermissionActionSchema instead of a hand-written action guard, and bring the Grok section of docs/reference/file-formats.md in line with the new import behaviour. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Regenerate src/generated/docs-content.ts over the merged docs, and clarify in the class docstring that the verbose tool lookup also accepts the documented 'mcp' alias rather than only the shared tool table. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Part of #2498 (the
[permission] rulesimport slice from the 2026-08-06 comment)Problem
Grok's settings reference documents two permission forms under
[permission]: the compactallow/deny/askarrays of Claude-style entries, and the verboserules = [{ action = "allow", tool = "bash", pattern = "git *" }]tables.parseGrokPermissionArraysinsrc/features/permissions/grokcli-permissions.tsread only the three string arrays and returnednullwhen all of them were empty or absent. A config written entirely in the verbose form therefore imported to empty canonical permissions and fell back to the coarse[ui] permission_mode; therulesarray survived only as a preserved foreign key.Change
toRulesyncPermissionsnow also walks[[permission.rules]]:parseGrokRulemaps thetool+patternfields instead of callingparseGrokEntryon a table.MCPToolfolds its address into the canonical category exactly as the compact form does, so both forms produce the samemcp__<address>shape.toolfield is matched case-insensitively against the existing tool table. The settings reference writes the verbose form lowercase (tool = "bash") while the compact entries are capitalized (Bash(git *)), so accepting both spellings is what makes the documented example actually import.patternapplies to the whole tool (canonical*). Malformed entries (non-table, unknownaction, non-stringtool) and tools with no canonical equivalent are skipped, matching how unparseable compact entries are already handled.ACTION_RANKcomparison (deny > ask > allow) rather than relying on apply order, so precedence holds across sources.rulesarray counts as "fine-grained rules present", so the coarsepermission_modefallback is not taken even when every individual rule turns out to be unsupported.Not resolved here
Export stays on the compact array form. Generate-side coexistence with a user's untouched
rulesarray is not resolved by this PR: the array is still preserved verbatim and is not reconciled against the arrays rulesync writes. The class docstring states this explicitly.#2498stays open — itssandbox.tomldeny-glob ignore-adapter gap is untouched.Tests
src/features/permissions/grokcli-permissions.test.ts: verbose-only config imports to canonical (withalways-approvepresent, proving the fallback is skipped); mixed rules + arrays resolve strictest-wins; missingpatternbecomes*; lowercase and capitalized tool names both parse; malformed/unsupported rules are skipped without triggering the fallback.src/e2e/e2e-permissions.spec.ts: a new grokcli import case driving the verbose form end to end.Full
pnpm cicheckpasses; the e2e permissions spec was run explicitly.🤖 Generated with Claude Code