diff --git a/.agents/install.py b/.agents/install.py index 6f7360e9f..41000f735 100755 --- a/.agents/install.py +++ b/.agents/install.py @@ -10,7 +10,7 @@ python .agents/install.py --target anthropic --scope user python .agents/install.py --target openai google --scope project --project-dir ~/my_study python .agents/install.py --list - python .agents/install.py --target openai --scope user --uninstall + python .agents/install.py --target openai --scope user --uninstall --dry-run Destinations: anthropic (Claude Code) skills: .claude/skills/ agents: .claude/agents/.md @@ -360,12 +360,16 @@ def main(): help='Agents to install (default: every agent whose skills are installed); give none to skip agents') parser.add_argument('--model-map', default=None, help='JSON file with model-map entries overriding model_map.json') parser.add_argument('--link', action='store_true', help='Symlink skills to this repository instead of copying them') - parser.add_argument('--force', action='store_true', help='Replace existing skills/agents with the same names') - parser.add_argument('--uninstall', action='store_true', help='Remove the selected skills/agents from the destination') + parser.add_argument('--force', action='store_true', help='Allow replacement or removal of existing skills/agents') + parser.add_argument('--uninstall', action='store_true', + help='Remove selected skills/agents. Use --dry-run to preview or --force to remove.') parser.add_argument('--dry-run', action='store_true', help='Show what would be done without changing anything') parser.add_argument('--list', action='store_true', help='List the available skills and agents, then exit') args = parser.parse_args() + if args.uninstall and not (args.list or args.dry_run or args.force): + parser.error('--uninstall can delete existing user files. Use --dry-run to preview or --force to remove.') + agents = read_agents() skills = available_skills() if args.list: diff --git a/.agents/tests/test_install_safe_uninstall.py b/.agents/tests/test_install_safe_uninstall.py new file mode 100644 index 000000000..f84d46d8d --- /dev/null +++ b/.agents/tests/test_install_safe_uninstall.py @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: LGPL-3.0-only +"""Exercise uninstall safety from the command line in an isolated project.""" +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + + +INSTALL = Path(__file__).resolve().parents[1] / 'install.py' + + +class UninstallSafetyTests(unittest.TestCase): + def setUp(self): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + self.project = Path(directory.name) + + def install(self, *args, expected_exit=0): + result = subprocess.run( + [sys.executable, str(INSTALL), '--scope', 'project', '--project-dir', + str(self.project), *args], + stdin=subprocess.DEVNULL, capture_output=True, text=True, check=False, + ) + self.assertEqual(result.returncode, expected_exit, result.stdout + result.stderr) + return result.stdout + result.stderr + + def test_uninstall_requires_force(self): + marker = self.project / '.claude/skills/thincurr-run/user-file' + marker.parent.mkdir(parents=True) + marker.write_text('user content') + target = ('--target', 'anthropic', '--skills', 'thincurr-run') + self.assertIn('exists', self.install(*target)) + self.assertIn('--force', self.install(*target, '--uninstall', expected_exit=2)) + self.assertIn(str(marker.parent), self.install(*target, '--uninstall', '--dry-run')) + self.assertEqual(marker.read_text(), 'user content') + self.install(*target, '--uninstall', '--force') + self.assertFalse(marker.exists()) diff --git a/AGENTS.md b/AGENTS.md index 882dd49ac..1d04264ac 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -94,9 +94,12 @@ python .agents/install.py --target anthropic openai --scope user Skills are copied unchanged (`--link` symlinks them instead); agents are translated from `.claude/agents/` to each tool's format. Hardcoded agent models are mapped -through `.agents/model_map.json` (edit it, or pass `--model-map FILE`). `--list`, -`--dry-run`, `--force`, and `--uninstall` do what they say. Keep skills and agents -free of paths into this repository (use `/scripts/...`), and when adding +through `.agents/model_map.json` (edit it, or pass `--model-map FILE`). +Preview removal with `--uninstall --dry-run`. Actual removal requires +`--uninstall --force` because the installer can delete existing user files. + +Keep skills and agents free of paths into this repository (use +`/scripts/...`), and when adding agent frontmatter fields, check that `install.py` translates or drops them: Codex and Gemini CLI reject agent files with unknown keys.