Refuse a security-review or claude-security Skill call from the worker's own context below the project's rung

This commit is contained in:
2026-10-30 13:10:56 +01:00
parent 0bb6f54a3c
commit a212b4ef91
9 changed files with 63 additions and 13 deletions
+3 -1
View File
@@ -3,7 +3,7 @@
usage: rule-hook (a PreToolUse hook: reads the call as JSON on stdin)
rule-hook overrides (prints this chunk's overrides)
settings.json runs it before each Agent, Bash, Edit, MultiEdit, Read and Write call, in every session and
settings.json runs it before each Agent, Bash, Edit, MultiEdit, Read, Skill and Write call, in every session and
subagent. The rules:
{rules}
@@ -76,6 +76,8 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
"""The text that may carry an override, what the log names the call by, and its breaches; None for a call no rule checks."""
if call.tool == "Agent":
return text(call.given, "prompt"), text(call.given, "subagent_type"), reviewer_breaches(call, environ)
if call.tool == "Skill":
return text(call.given, "args"), text(call.given, "skill"), reviewer_breaches(call, environ)
if call.tool == "Bash":
command = text(call.given, "command")
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + read_breaches(call, home)
+14 -4
View File
@@ -1,4 +1,4 @@
"""Refuse an Agent call that launches a review below the rung it needs, worked out from the rungs and the E + I loop-claude hands its worker: docs/decisions.md → `routing:`."""
"""Refuse an Agent or Skill call that launches a review below the rung it needs, worked out from the rungs and the E + I loop-claude hands its worker: docs/decisions.md → `routing:`."""
import pathlib
import typing
@@ -18,24 +18,28 @@ SEAT = "You are one seat of a comprehension panel."
# The opening of the security pass's prompt: skills/larv-review/SKILL.md → "Security".
SECURITY_OPENER = "You are the security pass for this chunk."
SUBJECTS: dict[ReviewKind, str] = {"seat": "a comprehension seat", "security": "the security pass's subagent"}
# The skills that run the security pass, by their names with any plugin prefix cut.
SECURITY_SKILLS = {"security-review", "claude-security"}
# Markdown an agent follows, which counts as config: Claude Code's memory files, and the folders that hold Claude Code's skills, agents and rules and this repo's principles.
INSTRUCTION_FILES = {"CLAUDE.md", "AGENTS.md"}
INSTRUCTION_FOLDERS = {"agents", "principles", "rules", "skills"}
def reviewer_breaches(call: Call, environ: typing.Mapping[str, str]) -> list[Breach]:
"""The breach of an Agent call that launches a review below its rung; none where loop-claude handed no rungs."""
"""The breach of an Agent or Skill call that launches a review below its rung; none where loop-claude handed no rungs."""
project, worker, escape_and_impact = handed(environ)
kind = review_kind(call.given)
kind = security_skill(call) if call.tool == "Skill" else review_kind(call.given)
if kind is None or project is None or worker is None:
return []
required = review_rungs(project, worker, escape_and_impact)[kind]
# A branch that changes only Markdown no agent follows holds no code or config for a reviewer on a higher rung to catch a defect in: skills/larv-review/SKILL.md → "Markdown only".
if kind in REVIEWERS and position(required) > position(project) and markdown_only(call.cwd):
required = project
named = named_rung(call.given, worker)
named = worker if call.tool == "Skill" else named_rung(call.given, worker)
if position(named) >= position(required):
return []
if call.tool == "Skill":
return [Breach("reviewer-rung", f"{text(call.given, 'skill')} would run in this context on {named}, below {required}: invoke it from a subagent launched with {required.agent_args()}, its prompt opening with `{SECURITY_OPENER}`", call.cwd)]
subject = SUBJECTS.get(kind) or text(call.given, "subagent_type")
return [Breach("reviewer-rung", f"{subject} would run on {named}, below {required}: launch it with {required.agent_args()}", call.cwd)]
@@ -52,6 +56,12 @@ def review_kind(given: dict[str, typing.Any]) -> ReviewKind | None:
return None
def security_skill(call: Call) -> ReviewKind | None:
"""The security pass, for a Skill call from the session's own agent that runs it; None for any other. A subagent's Skill call runs on the rung its Agent call was held to."""
skill = text(call.given, "skill").lstrip("/").rsplit(":", 1)[-1]
return "security" if skill in SECURITY_SKILLS and not call.agent else None
def named_rung(given: dict[str, typing.Any], worker: Rung) -> Rung:
"""The rung an Agent call's model and effort name. A call naming no model runs on the worker's model, at the effort it names or else the worker's; one naming a model but no effort runs on that model's cheapest rung."""
model, effort = text(given, "model"), text(given, "effort")
+1 -1
View File
@@ -61,7 +61,7 @@ RULES: dict[RuleName, Rule] = {
# A rung is not a judgment call, and the refusal names the arguments to pass, so no marker waives it.
"reviewer-rung": Rule(
"a reviewer, a comprehension seat or the security pass's subagent runs on the rung loop-claude names for it: for a seat or the security pass the project's rung, and for a reviewer the highest of the project's rung, the worker's and the one the chunk's item's E + I picks, or the project's rung where the branch changes only Markdown no agent follows, so a worker below the project's rung cannot hand a review to its own cheaper model",
"an Agent call, in a claude loop-claude started, whose subagent type is an agent under agents/, or whose prompt opens with seat-prompts.md's opening sentence or the one larv-review's Security section sets",
"an Agent call, in a claude loop-claude started, whose subagent type is an agent under agents/, or whose prompt opens with seat-prompts.md's opening sentence or the one larv-review's Security section sets; and a Skill call there of `security-review` or `claude-security` from the session's own agent, which runs on the worker's rung",
overridable=False,
),
# The cap holds with no ask, so no marker waives it.
+25
View File
@@ -315,6 +315,31 @@ class ReviewerRung(unittest.TestCase):
def test_a_claude_loop_claude_did_not_start_is_not_checked(self):
self.assertEqual(self.refused({"subagent_type": "stability-reviewer", "model": "haiku", "effort": "low"}, {}), [])
def test_a_security_skill_in_the_sessions_own_context_runs_on_the_workers_rung(self):
for skill in ("security-review", "claude-security", "claude-security:claude-security"):
with self.subTest(skill=skill):
breaches = reviewer_breaches(Call("Skill", {"skill": skill}, "/r"), self.ENVIRON)
self.assertEqual(rules(breaches), ["reviewer-rung"])
self.assertIn("claude-sonnet-5-5 at high effort", breaches[0].detail)
self.assertIn("model opus, effort medium", breaches[0].detail)
self.assertIn("You are the security pass for this chunk.", breaches[0].detail)
self.assertEqual(rules(reviewer_breaches(Call("Skill", {"skill": skill}, "/r"), self.ABOVE)), [])
def test_a_security_skill_inside_a_subagent_runs_on_the_rung_its_launch_was_held_to(self):
self.assertEqual(rules(reviewer_breaches(Call("Skill", {"skill": "security-review"}, "/r", "general-purpose"), self.ENVIRON)), [])
def test_any_other_skill_is_not_checked(self):
self.assertEqual(rules(reviewer_breaches(Call("Skill", {"skill": "simplify"}, "/r"), self.ENVIRON)), [])
def test_a_skill_calls_args_are_the_text_scanned_for_a_marker(self):
found = breaches_of(Call("Skill", {"skill": "security-review", "args": "the branch # rule-override reviewer-rung: trust me"}, "/r"), "/h", {})
self.assertEqual(found[:2], ("the branch # rule-override reviewer-rung: trust me", "security-review"))
def test_settings_run_the_hook_before_each_skill_call(self):
settings = json.loads(pathlib.Path(__file__).resolve().parents[2].joinpath("settings.json").read_text())
matchers = [entry["matcher"].split("|") for entry in settings["hooks"]["PreToolUse"]]
self.assertTrue(any("Skill" in tools for tools in matchers))
class ReviewerReport(unittest.TestCase):
def breached(self, tool: str, path: str, agent: str = "prose-reviewer", cwd: str = "/r") -> list[str]: