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>
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const COUNCIL_DENY = ["Edit(~/.claude/agents-council/**)", "Edit(~/.local/state/agents-council/**)"];
|
|
|
|
function withCouncilDeny(data) {
|
|
data.permissions = data.permissions || {};
|
|
data.permissions.deny = [...new Set([...(data.permissions.deny || []), ...COUNCIL_DENY])];
|
|
return data;
|
|
}
|
|
|
|
module.exports = { COUNCIL_DENY, withCouncilDeny };
|
|
|
|
function resolved(settingsPath) {
|
|
let link;
|
|
try {
|
|
link = fs.lstatSync(settingsPath).isSymbolicLink();
|
|
} catch (err) {
|
|
if (err.code === "ENOENT") return settingsPath;
|
|
throw err;
|
|
}
|
|
if (!link) return settingsPath;
|
|
if (fs.existsSync(settingsPath)) return fs.realpathSync(settingsPath);
|
|
return path.resolve(path.dirname(settingsPath), fs.readlinkSync(settingsPath));
|
|
}
|
|
|
|
function main(settingsPath) {
|
|
if (!settingsPath) {
|
|
console.error("usage: council-deny.js <settings.json>");
|
|
return 2;
|
|
}
|
|
const target = resolved(settingsPath);
|
|
let data = {};
|
|
let mode = 0o600;
|
|
if (fs.existsSync(target)) {
|
|
mode = fs.statSync(target).mode & 0o777;
|
|
const raw = fs.readFileSync(target, "utf8").trim();
|
|
if (raw) {
|
|
try {
|
|
data = JSON.parse(raw);
|
|
} catch (err) {
|
|
console.error(`skills: ${settingsPath} is not valid JSON; leaving it untouched (${err.message}).`);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
console.error(`skills: ${settingsPath} holds no JSON object; leaving it untouched.`);
|
|
return 1;
|
|
}
|
|
const temporary = `${target}.${process.pid}`;
|
|
try {
|
|
fs.writeFileSync(temporary, JSON.stringify(withCouncilDeny(data), null, 2) + "\n", { mode, flag: "wx" });
|
|
fs.chmodSync(temporary, mode);
|
|
fs.renameSync(temporary, target);
|
|
} catch (err) {
|
|
fs.rmSync(temporary, { force: true });
|
|
throw err;
|
|
}
|
|
console.log(`skills: Edit and Write on ${COUNCIL_DENY.length} council paths denied in ${settingsPath}`);
|
|
return 0;
|
|
}
|
|
|
|
if (require.main === module) process.exit(main(process.argv[2]));
|