Skip to content

fix(import): keep rule scopes, split hook matchers, keep UTF-8 text - #490

Merged
mrnasil merged 2 commits into
mainfrom
fix/import-jsonc-scope
Nov 25, 2026
Merged

mrnasil merged 2 commits into
mainfrom
fix/import-jsonc-scope

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

Importing another tool's settings could change what they meant in three ways.

Permission scopes were dropped. An allow for Bash(npm test) became bash = allow, which auto-runs every shell command. A deny for Read(./.env) became a deny on every read. Scoped rules now map to the scoped keys core already understands (bash(npm test), read(./.env), edit(src/**)). A scope on a tool that has no scoped rules (WebFetch(domain:…)) is reported as not mapped instead of being widened. Read(*) still maps to plain read.

Hook matchers are regexes. Edit|Write became one tool name that never matched anything, so the hook was silently dead. Each alternative now becomes its own hook, and duplicates are removed (Edit|Write|MultiEdit gives one edit hook). A trailing .* becomes *, and an empty matcher or * matches every tool. Any other regex syntax is reported as skipped instead of producing a hook that never fires.

Non-ASCII text was garbled. strip_jsonc pushed each UTF-8 byte as a char, so a path like C:/Users/Çağrı/x.py was imported garbled, and the imported MCP server or hook failed to start. It now copies bytes. It also drops a trailing comma when a comment sits between it and the closing bracket.

Tests: each case has a test, and two existing assertions that encoded the widening were updated. parse.rs has 100% line coverage.

🤖 Generated with Claude Code

Three ways importing another tool's settings changed their meaning:

- Permission rules lost their scope: an allow for `Bash(npm test)`
  became `bash = allow`, auto-running every shell command, and a deny
  for `Read(./.env)` denied every read. Scoped rules now map to the
  scoped keys core already understands (`bash(npm test)`,
  `read(./.env)`); a scope on a tool without scoped rules is reported as
  not mapped instead of widened.
- Hook matchers are regexes. `Edit|Write` became one tool name that
  never matched, so the hook was silently dead. Alternatives now become
  one hook each, `.*` suffixes become `*`, and any other regex syntax is
  reported as skipped.
- strip_jsonc pushed each UTF-8 byte as a char, so every non-ASCII
  string (paths with `Çağrı`, for one) came out garbled. It now copies
  bytes, and also drops a trailing comma that a comment separates from
  the closing bracket.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil enabled auto-merge (squash) November 25, 2026 15:00
@mrnasil
mrnasil merged commit 4307e69 into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/import-jsonc-scope branch November 25, 2026 21:20
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
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.

1 participant