Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(claude): remove distill allow rules on uninstall and check in leftover reason (#2483)
Rishabh Mishra3ffce99938b4
diff --git a/packages/cli/src/repowise/cli/agent_adapters/claude_code.py b/packages/cli/src/repowise/cli/agent_adapters/claude_code.pyindex 5c75e88ea..295306ff1 100644--- a/packages/cli/src/repowise/cli/agent_adapters/claude_code.py+++ b/packages/cli/src/repowise/cli/agent_adapters/claude_code.py@@ -122,10 +122,13 @@ class ClaudeCodeAdapter(AgentAdapter):def uninstall_rewrite_hook(self) -> bool:from repowise.cli.editor_integrations.claude_config import (+ uninstall_claude_code_distill_allow_rules,uninstall_claude_code_rewrite_hook,)- return uninstall_claude_code_rewrite_hook()+ hook_removed = uninstall_claude_code_rewrite_hook()+ rules_removed = uninstall_claude_code_distill_allow_rules()+ return hook_removed or rules_removeddef rewrite_hook_installed(self) -> bool:from repowise.cli.editor_integrations.claude_config import (diff --git a/packages/cli/src/repowise/cli/agent_targets/targets/claude_code.py b/packages/cli/src/repowise/cli/agent_targets/targets/claude_code.pyindex 923d0bb27..ca59d3db5 100644--- a/packages/cli/src/repowise/cli/agent_targets/targets/claude_code.py+++ b/packages/cli/src/repowise/cli/agent_targets/targets/claude_code.py@@ -440,6 +440,7 @@ class ClaudeCodeTarget:claude_code_leftover_reason,claude_desktop_leftover_reason,uninstall_claude_code_augment_hooks,+ uninstall_claude_code_distill_allow_rules,uninstall_claude_code_mcp_entry,uninstall_claude_code_rewrite_hook,uninstall_claude_desktop_mcp_entry,@@ -458,6 +459,7 @@ class ClaudeCodeTarget:# `or` would skip the later removals whenever an earlier one succeeded.removed = uninstall_claude_code_rewrite_hook()removed = uninstall_claude_code_augment_hooks() or removed+ removed = uninstall_claude_code_distill_allow_rules() or removedremoved = uninstall_claude_code_mcp_entry() or removed# The Desktop config too, because `install` writes it and `detect` reads# it. Leaving it made a removed Claude Code still look wired, so thediff --git a/packages/cli/src/repowise/cli/editor_integrations/claude_config.py b/packages/cli/src/repowise/cli/editor_integrations/claude_config.pyindex c6dbc6ed8..78087b92f 100644--- a/packages/cli/src/repowise/cli/editor_integrations/claude_config.py+++ b/packages/cli/src/repowise/cli/editor_integrations/claude_config.py@@ -556,6 +556,41 @@ def add_claude_code_distill_allow_rules() -> Path | None:return settings_path+def uninstall_claude_code_distill_allow_rules() -> bool:+ """Remove the distill allow rules from ``permissions.allow`` in settings.json.++ Returns True when at least one rule was removed and saved, False otherwise.+ Strictly removes only rules matching DISTILL_ALLOW_RULES; user rules survive.+ """+ settings_path = _claude_code_settings_path()+ if not settings_path.exists():+ return False+ try:+ existing = load_existing_config(settings_path)+ except Exception:+ return False++ permissions = existing.get("permissions")+ if not isinstance(permissions, dict):+ return False+ allow = permissions.get("allow")+ if not isinstance(allow, list):+ return False++ initial_len = len(allow)+ allow[:] = [rule for rule in allow if rule not in DISTILL_ALLOW_RULES]+ if len(allow) == initial_len:+ return False++ if not allow:+ permissions.pop("allow", None)+ if not permissions:+ existing.pop("permissions", None)++ return _write_settings(settings_path, existing)+++def _migrate_legacy_rewrite_matcher(hook_list: list) -> bool:"""Widen legacy rewrite-hook matchers in place (``Bash`` → current)."""changed = False@@ -748,6 +783,12 @@ def claude_code_leftover_reason() -> str | None:_is_repowise_hook(hook) or _is_rewrite_hook(hook)):return "one of our hooks was still present after the write"++ permissions = existing.get("permissions")+ if isinstance(permissions, dict):+ allow = permissions.get("allow")+ if isinstance(allow, list) and any(r in DISTILL_ALLOW_RULES for r in allow):+ return "our distill permission rules were still present after the write"return Nonediff --git a/tests/unit/distill/test_allow_rule.py b/tests/unit/distill/test_allow_rule.pyindex a7e1e55a1..95eb1c673 100644--- a/tests/unit/distill/test_allow_rule.py+++ b/tests/unit/distill/test_allow_rule.py@@ -18,6 +18,8 @@ from repowise.cli.editor_integrations import claude_configfrom repowise.cli.editor_integrations.claude_config import (DISTILL_ALLOW_RULES,add_claude_code_distill_allow_rules,+ claude_code_leftover_reason,+ uninstall_claude_code_distill_allow_rules,)@@ -84,6 +86,45 @@ class TestAddDistillAllowRules:assert add_claude_code_distill_allow_rules() is None+class TestUninstallDistillAllowRules:+ def test_removes_rules_and_cleans_empty_permissions(self, settings_path) -> None:+ add_claude_code_distill_allow_rules()+ assert claude_code_leftover_reason() == "our distill permission rules were still present after the write"+ assert uninstall_claude_code_distill_allow_rules() is True+ assert claude_code_leftover_reason() is None+ data = json.loads(settings_path.read_text(encoding="utf-8"))+ assert "permissions" not in data++ def test_preserves_user_allow_rules(self, settings_path) -> None:+ settings_path.parent.mkdir(parents=True, exist_ok=True)+ settings_path.write_text(+ json.dumps(+ {+ "permissions": {+ "allow": ["Bash(git status:*)", *DISTILL_ALLOW_RULES],+ "deny": ["WebFetch"],+ }+ }+ ),+ encoding="utf-8",+ )+ assert claude_code_leftover_reason() == "our distill permission rules were still present after the write"+ assert uninstall_claude_code_distill_allow_rules() is True+ assert claude_code_leftover_reason() is None+ allow = _allow(settings_path)+ assert allow == ["Bash(git status:*)"]+ data = json.loads(settings_path.read_text(encoding="utf-8"))+ assert data["permissions"]["deny"] == ["WebFetch"]++ def test_returns_false_when_absent(self, settings_path) -> None:+ assert uninstall_claude_code_distill_allow_rules() is False++ def test_returns_false_on_malformed_file(self, settings_path) -> None:+ settings_path.parent.mkdir(parents=True, exist_ok=True)+ settings_path.write_text("{not json", encoding="utf-8")+ assert uninstall_claude_code_distill_allow_rules() is False++class TestRewriteInstallFlag:"""--allow-rule / --no-allow-rule plumbing on `hook rewrite install`."""