feat(install): deny Edit and Write on the council config and state in every session
New scripts/council-deny.js holds the deny rules (SPOT) for ~/.claude/agents-council/** and, new, ~/.local/state/agents-council/**, where the skills' scripts keep state only they may change. enable-plugins.js takes them from it for <TARGET>/.claude/settings.local.json as before. The global install now also merges them into ~/.claude/settings.json, the only user-wide settings file, because a settings.local.json binds only sessions rooted in its own repository; the operator no longer edits settings by hand. The writer follows a settings symlink (dangling included), keeps the file mode, writes a 0600 wx temp file and renames it, and refuses invalid JSON or a non-object with exit 1 and the file untouched. Tests: tests/test_dream.py 26 passed (denies once beside existing rules, user settings kept through a symlink with mode, dangling link kept, invalid JSON untouched with exit 1); two independent reviews, round 2 holds. 🎯 Fix: 93 % 💥 Break: 3 % 💸 Cost: 100 % ⏱️ Time: 100 % 🛡️ Security: 100 % 🏆 Score: 90 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3418738993
commit
c17ac79258
5 files changed
+111
-6
No files matched your search
+39
-2
@@ -17,6 +17,8 @@ NOTIFY = DREAM / "hooks" / "notify.sh"
|
||||
TIMER = DREAM / "systemd" / "kvb-dream-notify.timer"
|
||||
SERVICE = DREAM / "systemd" / "kvb-dream-notify.service"
|
||||
PATCHER = REPO_ROOT / "scripts" / "enable-plugins.js"
|
||||
COUNCIL_DENY = REPO_ROOT / "scripts" / "council-deny.js"
|
||||
DENIED = ["Edit(~/.claude/agents-council/**)", "Edit(~/.local/state/agents-council/**)"]
|
||||
|
||||
|
||||
class TestDreamSkill(unittest.TestCase):
|
||||
@@ -278,13 +280,48 @@ class TestSettingsRegistration(unittest.TestCase):
|
||||
with self.subTest(command=command):
|
||||
self.assertTrue(command.startswith("/usr/bin/bash "))
|
||||
|
||||
def test_council_config_deny_is_added_once_next_to_existing_rules(self):
|
||||
def test_council_config_and_state_denies_are_added_once_next_to_existing_rules(self):
|
||||
self.settings.write_text(json.dumps({"permissions": {"deny": ["Bash(rm -rf:*)"]}}), encoding="utf-8")
|
||||
self._patch()
|
||||
self.assertEqual(self._patch()["permissions"]["deny"], ["Bash(rm -rf:*)", *DENIED])
|
||||
|
||||
def _deny(self, path: Path) -> subprocess.CompletedProcess:
|
||||
return subprocess.run(["node", str(COUNCIL_DENY), str(path)], capture_output=True, text=True, check=False)
|
||||
|
||||
def test_the_user_settings_get_the_council_denies_once_and_keep_everything_else(self):
|
||||
real = Path(self.tmp.name) / "dotfiles" / "settings.json"
|
||||
real.parent.mkdir()
|
||||
real.write_text(json.dumps({"model": "opus", "permissions": {"deny": ["Bash(rm -rf:*)"], "ask": ["Bash(git push:*)"]}}), encoding="utf-8")
|
||||
real.chmod(0o640)
|
||||
self.settings.symlink_to(real)
|
||||
for _ in range(2):
|
||||
self.assertEqual(self._deny(self.settings).returncode, 0)
|
||||
self.assertTrue(self.settings.is_symlink())
|
||||
self.assertEqual(real.stat().st_mode & 0o777, 0o640)
|
||||
self.assertEqual(
|
||||
self._patch()["permissions"]["deny"], ["Bash(rm -rf:*)", "Edit(~/.claude/agents-council/**)"]
|
||||
json.loads(real.read_text(encoding="utf-8")),
|
||||
{"model": "opus", "permissions": {"deny": ["Bash(rm -rf:*)", *DENIED], "ask": ["Bash(git push:*)"]}},
|
||||
)
|
||||
|
||||
def test_a_dangling_settings_link_keeps_its_link_and_gets_its_file(self):
|
||||
real = Path(self.tmp.name) / "dotfiles" / "settings.json"
|
||||
real.parent.mkdir()
|
||||
self.settings.symlink_to(real)
|
||||
self.assertEqual(self._deny(self.settings).returncode, 0)
|
||||
self.assertTrue(self.settings.is_symlink())
|
||||
self.assertEqual(real.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(json.loads(real.read_text(encoding="utf-8")), {"permissions": {"deny": DENIED}})
|
||||
self.assertEqual(sorted(p.name for p in real.parent.iterdir()), ["settings.json"])
|
||||
|
||||
def test_user_settings_that_are_no_json_object_stay_untouched_and_fail_the_install(self):
|
||||
for content in ("{not json", "[]"):
|
||||
with self.subTest(content=content):
|
||||
self.settings.write_text(content, encoding="utf-8")
|
||||
done = self._deny(self.settings)
|
||||
self.assertEqual(done.returncode, 1)
|
||||
self.assertIn("leaving it untouched", done.stderr)
|
||||
self.assertEqual(self.settings.read_text(encoding="utf-8"), content)
|
||||
|
||||
def test_plugin_skills_are_not_copied_twice(self):
|
||||
skills = Path(self.tmp.name) / "skills"
|
||||
for name in ("caveman", "ponytail-review", "cavecrew", "archify", "kvb-dream"):
|
||||
|
||||
Reference in new issue
Block a user