Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(cli): clear distill.commands.enabled and remove AGENTS.md on hook rewrite uninstall (#2491)

Rishabh Mishrab40fc2aa4fdf
diff --git a/packages/cli/src/repowise/cli/commands/hook_cmd.py b/packages/cli/src/repowise/cli/commands/hook_cmd.py
index 66442488f..ae58453fc 100644
--- a/packages/cli/src/repowise/cli/commands/hook_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/hook_cmd.py
@@ -350,6 +350,10 @@ def rewrite_uninstall(path: str | None, workspace: bool, no_workspace: bool) ->
"""Remove the rewrite hooks and the AGENTS.md awareness section."""
from repowise.cli.agent_adapters.claude_code import ClaudeCodeAdapter
from repowise.cli.agent_adapters.codex import CodexAdapter
+ from repowise.cli.editor_integrations.codex_config import (
+ remove_agents_md_distill_section,
+ )
+ from repowise.cli.helpers import save_distill_commands_enabled
removed = ClaudeCodeAdapter().uninstall_rewrite_hook()
console.print(f"Rewrite hook: {'[green]removed[/green]' if removed else 'not installed'}")
@@ -360,14 +364,23 @@ def rewrite_uninstall(path: str | None, workspace: bool, no_workspace: bool) ->
console.print(
f"Codex rewrite hook: {'[green]removed[/green]' if codex_removed else 'not installed'}"
)
- from repowise.cli.editor_integrations.codex_config import (
- remove_agents_md_distill_section,
- )
- target = _hook_target(path, workspace, no_workspace)
- for repo_path in _target_repo_paths(target):
- if remove_agents_md_distill_section(repo_path):
- console.print(f" [green]✓[/green] AGENTS.md distill section removed ({repo_path})")
+ target = _hook_target(path, workspace, no_workspace)
+ for repo_path in _target_repo_paths(target):
+ if remove_agents_md_distill_section(repo_path):
+ console.print(f" [green]✓[/green] AGENTS.md distill section removed ({repo_path})")
+
+ if target.is_workspace:
+ assert target.ws_root is not None and target.ws_config is not None
+ for entry in target.ws_config.repos:
+ abs_path = (target.ws_root / entry.path).resolve()
+ if (abs_path / ".repowise").is_dir():
+ save_distill_commands_enabled(abs_path, enabled=False)
+ console.print(f" {entry.alias}: [yellow]disabled[/yellow]")
+ else:
+ assert target.repo_path is not None
+ if (target.repo_path / ".repowise").is_dir():
+ save_distill_commands_enabled(target.repo_path, enabled=False)
@rewrite_group.command("status")
diff --git a/tests/unit/distill/test_config_and_doctor.py b/tests/unit/distill/test_config_and_doctor.py
index d502ad215..b643a5a1d 100644
--- a/tests/unit/distill/test_config_and_doctor.py
+++ b/tests/unit/distill/test_config_and_doctor.py
@@ -311,7 +311,7 @@ def test_install_workspace_mode_re_enables_every_repo(
assert cfg["distill"]["commands"]["enabled"] is True
-def test_uninstall_removes_hook_but_leaves_repo_config(
+def test_uninstall_removes_hook_and_disables_repo_config(
tmp_path: Path, settings_path: Path, monkeypatch
) -> None:
from repowise.core.repo_config import load_repo_config
@@ -326,10 +326,36 @@ def test_uninstall_removes_hook_but_leaves_repo_config(
assert "removed" in result.output
data = json.loads(settings_path.read_text(encoding="utf-8"))
assert not data.get("hooks", {}).get("PreToolUse")
- # Uninstall is global (settings.json); per-repo config stays as-is so a
- # later reinstall does not need to re-discover repo preferences.
cfg = load_repo_config(repo)
- assert cfg["distill"]["commands"]["enabled"] is True
+ assert cfg["distill"]["commands"]["enabled"] is False
+
+
+def test_uninstall_workspace_disables_all_repo_configs(
+ tmp_path: Path, settings_path: Path, monkeypatch
+) -> None:
+ from repowise.core.repo_config import load_repo_config
+ from repowise.core.workspace.config import RepoEntry, WorkspaceConfig
+
+ root = tmp_path / "workspace"
+ root.mkdir(parents=True)
+ aliases = ("alpha", "beta")
+ for alias in aliases:
+ repo = root / alias
+ (repo / ".repowise").mkdir(parents=True)
+ WorkspaceConfig(repos=[RepoEntry(path=a, alias=a) for a in aliases], default_repo="alpha").save(
+ root
+ )
+ monkeypatch.chdir(root)
+
+ CliRunner().invoke(rewrite_install, ["--workspace"])
+ for alias in aliases:
+ assert load_repo_config(root / alias)["distill"]["commands"]["enabled"] is True
+
+ result = CliRunner().invoke(rewrite_uninstall, ["--workspace"])
+ assert result.exit_code == 0
+ assert "disabled" in result.output
+ for alias in aliases:
+ assert load_repo_config(root / alias)["distill"]["commands"]["enabled"] is False
# ---------------------------------------------------------------------------
@@ -408,6 +434,30 @@ def test_uninstall_removes_codex_hook_and_agents_md_section(
assert not (repo / "AGENTS.md").exists() # awareness section round-tripped away
+def test_uninstall_removes_agents_md_section_when_codex_not_detected(
+ tmp_path: Path, settings_path: Path, monkeypatch
+) -> None:
+ from repowise.cli.agent_adapters.codex import CodexAdapter
+ from repowise.cli.editor_integrations import codex_config
+
+ monkeypatch.setattr(CodexAdapter, "detect", lambda self: True)
+ monkeypatch.setattr(codex_config, "codex_cli_version", lambda: (0, 137, 0))
+ repo = _make_repo(tmp_path, monkeypatch)
+
+ # Install writes AGENTS.md while Codex is detected
+ CliRunner().invoke(rewrite_install, [])
+ assert (repo / "AGENTS.md").exists()
+ assert "REPOWISE_DISTILL" in (repo / "AGENTS.md").read_text(encoding="utf-8")
+
+ # Simulate Codex no longer detected
+ monkeypatch.setattr(CodexAdapter, "detect", lambda self: False)
+
+ result = CliRunner().invoke(rewrite_uninstall, [])
+ assert result.exit_code == 0
+ assert "AGENTS.md distill section removed" in result.output
+ assert not (repo / "AGENTS.md").exists()
+
+
def test_status_is_honest_about_codex_capability(
tmp_path: Path, settings_path: Path, codex_env: Path, monkeypatch
) -> None: