From a212b4ef91e48d3a7a9fc94c372f7ffa6499eb0e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 30 Oct 2026 13:10:56 +0100 Subject: [PATCH 1/5] Refuse a security-review or claude-security Skill call from the worker's own context below the project's rung --- CHANGELOG.md | 1 + README.md | 2 +- bin/rule_hook/main.py | 4 +++- bin/rule_hook/reviewer_rung.py | 18 ++++++++++++++---- bin/rule_hook/rules.py | 2 +- bin/rule_hook/test_rule_hook.py | 25 +++++++++++++++++++++++++ docs/reading-cost.md | 17 +++++++++++++++++ settings.json | 2 +- todo.md | 5 ----- 9 files changed, 63 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4290dff..d980f022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - A release review now fixes the findings of its architecture and principles passes in the release it reviews. Before, it filed each one in `todo.md`, so the release held the drift the review had found. It files only three kinds of finding, each under the release being reviewed: one whose fix needs a human answer, marked `question`; one whose fix adds a feature; and one whose fix the five rounds cannot finish. Until each is done, the release isn't ready to cut. - In a repo with no tag yet, `chunk-preflight` now calls a release finished once `todo.md` files no item under it: its release review is due, and no later release's item is taken. Before, it lost sight of such a release. +- In a run `loop-claude` started, `rule-hook` now refuses a `/security-review` or `/claude-security` Skill call that the worker makes in its own context on a rung below the project's. The refusal says to invoke it from a subagent on the project's rung. Before, only an Agent call that launched the security pass was held to that rung. ## 0.4.0 diff --git a/README.md b/README.md index e514944a..b8f30e02 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t - `rank_todo.py [--check] [todo.md]` scores and ranks a project's `todo.md`; `rank_todo.py --help` states the format. - `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure. - `review-replay ` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host. -- `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Agent, Bash, Edit, MultiEdit, Read and Write call, and `rule-hook --help` states the rules and the override. +- `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Agent, Bash, Edit, MultiEdit, Read, Skill and Write call, and `rule-hook --help` states the rules and the override. - `run-heavy ` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory cap it gives a container that sets no limit. - `score-outcomes [L E I S]` shows what each finished item's chunk measured beside the scores the item was guessed at, to score a new item by, and code health's two counter-signals per chunk, misread findings and later fixes; `score-outcomes --help` states the report. - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. diff --git a/bin/rule_hook/main.py b/bin/rule_hook/main.py index cc40d549..58b74f24 100644 --- a/bin/rule_hook/main.py +++ b/bin/rule_hook/main.py @@ -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) diff --git a/bin/rule_hook/reviewer_rung.py b/bin/rule_hook/reviewer_rung.py index 47622e18..496f1152 100644 --- a/bin/rule_hook/reviewer_rung.py +++ b/bin/rule_hook/reviewer_rung.py @@ -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") diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 880b109b..6846c9ee 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -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. diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index dccb1b5e..e8c85265 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -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]: diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 7c6ffc96..f33bd0d6 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -923,3 +923,20 @@ Read most (opens and searches): ## Reading cost, chunk cfd9ab4f5b1b, finished 2026-10-28T22:00:08Z 64114 new input tokens before the first commit. + +## Reading cost, chunk d8367f5dd24a, finished 2026-10-30T12:08:14Z + +144200 new input tokens before the first commit. + +Read most (opens and searches): + +- `docs/decisions.md` 6 +- `todo.md` 6 +- `AGENTS.md` 4 +- `bin/test_chunk_pick.py` 4 +- `README.md` 3 +- `skills/larv-review/SKILL.md` 3 +- `bin/loop_claude/running_loops.py` 2 +- `bin/loop_claude/test_black_box.py` 2 +- `bin/loop_inbox/main.py` 2 +- `bin/loop_inbox/test_loop_inbox.py` 2 diff --git a/settings.json b/settings.json index c7f82c95..40ebacf3 100644 --- a/settings.json +++ b/settings.json @@ -32,7 +32,7 @@ "type": "command" } ], - "matcher": "Agent|Bash|Edit|MultiEdit|Read|Write" + "matcher": "Agent|Bash|Edit|MultiEdit|Read|Skill|Write" } ] }, diff --git a/todo.md b/todo.md index 652266c4..1fb66d17 100644 --- a/todo.md +++ b/todo.md @@ -12,7 +12,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 167 | 0.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | | 257 | 0.5.0 | | | **Make `chunk-preflight` create the item's worktree and branch only when loop-claude starts a worker on it, so a run for the facts alone leaves nothing to remove.** | 3 | 2 | 3 | 6 | 4 | 1.5 by 2 | 1.3 | | 226 | 0.6.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | @@ -77,10 +76,6 @@ ## Details -### 167. Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call. - -rule-hook checks Agent calls (item 163) but no Skill calls. A worker that invokes `/security-review` in its own context, instead of in a subagent, runs the pass on its own rung, and nothing blocks it. Check Skill calls too: `breaches_of` in bin/rule_hook/main.py takes a Skill call whose skill is `security-review` or `claude-security` as a review launch, and settings.json's PreToolUse matcher gains Skill. Found by the systems-architect's review of PR #295. - ### 6. Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay. Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. -- 2.52.0 From 89aae3030c7effc28aa7f855c4095e8fb487193a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 30 Oct 2026 13:11:33 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20clean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 2ee9df2e07e01dc5552cf52df4baa8681c089408 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 30 Oct 2026 13:22:25 +0100 Subject: [PATCH 3/5] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20refuse=20a?= =?UTF-8?q?=20security=20skill=20in=20a=20subagent=20not=20launched=20as?= =?UTF-8?q?=20the=20security=20pass,=20split=20skill=5Fbreaches=20out,=20t?= =?UTF-8?q?ell=20a=20subagent=20by=20agent=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/rule_hook/call.py | 6 +++-- bin/rule_hook/main.py | 4 ++-- bin/rule_hook/reviewer_rung.py | 40 +++++++++++++++++++++++---------- bin/rule_hook/rules.py | 4 ++-- bin/rule_hook/test_rule_hook.py | 38 +++++++++++++++++++++++-------- 6 files changed, 66 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d980f022..5d69ee03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - A release review now fixes the findings of its architecture and principles passes in the release it reviews. Before, it filed each one in `todo.md`, so the release held the drift the review had found. It files only three kinds of finding, each under the release being reviewed: one whose fix needs a human answer, marked `question`; one whose fix adds a feature; and one whose fix the five rounds cannot finish. Until each is done, the release isn't ready to cut. - In a repo with no tag yet, `chunk-preflight` now calls a release finished once `todo.md` files no item under it: its release review is due, and no later release's item is taken. Before, it lost sight of such a release. -- In a run `loop-claude` started, `rule-hook` now refuses a `/security-review` or `/claude-security` Skill call that the worker makes in its own context on a rung below the project's. The refusal says to invoke it from a subagent on the project's rung. Before, only an Agent call that launched the security pass was held to that rung. +- In a run `loop-claude` started, `rule-hook` now refuses a `/security-review` or `/claude-security` Skill call that the worker makes in its own context on a rung below the project's. It also refuses one from any subagent whose prompt doesn't open with `You are the security pass for this chunk.`, since that subagent's rung is unchecked. The refusal says to invoke the skill from a subagent on the project's rung, its prompt opening with that sentence. Before, only an Agent call that launched the security pass was held to that rung. ## 0.4.0 diff --git a/bin/rule_hook/call.py b/bin/rule_hook/call.py index afd5d1e7..908007f9 100644 --- a/bin/rule_hook/call.py +++ b/bin/rule_hook/call.py @@ -12,10 +12,12 @@ class Call: tool: str given: dict[str, typing.Any] cwd: str - # The subagent the call comes from, such as prose-reviewer; empty for the session's own agent. + # The agent that makes the call, such as prose-reviewer, or the one a session was started with by --agent; empty for a session's default agent. agent: str = "" # The transcript of the agent that makes the call: a subagent's own, not its session's. transcript: str = "" + # Whether a subagent makes the call. + subagent: bool = False def parsed_call(hook_input: object) -> Call | Failure: @@ -29,7 +31,7 @@ def parsed_call(hook_input: object) -> Call | Failure: if isinstance(agent_id, str) and transcript: # Inside a subagent, transcript_path still names the session's transcript. transcript = subagent_transcript(transcript, agent_id) - return Call(tool, given, cwd, agent if isinstance(agent, str) else "", transcript) + return Call(tool, given, cwd, agent if isinstance(agent, str) else "", transcript, isinstance(agent_id, str)) def text(given: dict[str, typing.Any], key: str) -> str: diff --git a/bin/rule_hook/main.py b/bin/rule_hook/main.py index 58b74f24..01979067 100644 --- a/bin/rule_hook/main.py +++ b/bin/rule_hook/main.py @@ -43,7 +43,7 @@ from failure import Failure from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override from rule_hook.repeat_read import read_breaches from rule_hook.reviewer_report import report_breaches -from rule_hook.reviewer_rung import reviewer_breaches +from rule_hook.reviewer_rung import reviewer_breaches, skill_breaches from rule_hook.round_cap import round_cap_breaches from shell_command import simple_commands from rule_hook.todo_check import todo_breaches @@ -77,7 +77,7 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup 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) + return text(call.given, "args"), text(call.given, "skill"), skill_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) diff --git a/bin/rule_hook/reviewer_rung.py b/bin/rule_hook/reviewer_rung.py index 496f1152..923d9e9b 100644 --- a/bin/rule_hook/reviewer_rung.py +++ b/bin/rule_hook/reviewer_rung.py @@ -4,11 +4,13 @@ import typing from rule_hook.rules import Breach from rule_hook.call import Call, text +from claude_code.entries import content from failure import Failure from rule_hook.git import git import git_repo from model_routing.worker_rungs import handed from model_routing.ladder import position, review_rungs, ReviewKind, Rung +from claude_code.transcript import read_transcript from review_passes import REVIEWERS # The pass each agent under agents/ reviews. @@ -19,31 +21,51 @@ SEAT = "You are one seat of a comprehension panel." 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"} +SECURITY_SKILLS = {"claude-security", "security-review"} # 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 or Skill call that launches a review below its rung; none where loop-claude handed no rungs.""" + """The breach of an Agent call that launches a review below its rung; none where loop-claude handed no rungs.""" project, worker, escape_and_impact = handed(environ) - kind = security_skill(call) if call.tool == "Skill" else review_kind(call.given) + kind = 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 = worker if call.tool == "Skill" else named_rung(call.given, worker) + named = 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)] +def skill_breaches(call: Call, environ: typing.Mapping[str, str]) -> list[Breach]: + """The breach of a Skill call that runs the security pass below the project's rung; none where loop-claude handed no rungs. + + The skill runs on its caller's rung. A subagent launched as the security pass was held to the project's rung by reviewer_breaches. The worker's own rung is known, so its call is refused only below the project's rung. Any other subagent's rung is unknown, so its call is refused.""" + project, worker, _ = handed(environ) + skill = text(call.given, "skill").lstrip("/").rsplit(":", 1)[-1] + if skill not in SECURITY_SKILLS or project is None or worker is None or opening_prompt(call.transcript).startswith(SECURITY_OPENER): + return [] + if not call.subagent and position(worker) >= position(project): + return [] + runs_on = "on a rung rule-hook cannot see" if call.subagent else f"in this context on {worker}, below {project}" + return [Breach("reviewer-rung", f"{skill} would run {runs_on}: invoke it from a subagent launched with {project.agent_args()}, its prompt opening with `{SECURITY_OPENER}`", call.cwd)] + + +def opening_prompt(transcript: str) -> str: + """The prompt a transcript opens with, such as a subagent's from its Agent call; empty where it cannot be read.""" + entries = read_transcript(transcript) if transcript else [] + first = entries[0] if isinstance(entries, list) and entries else {} + prompt = content(first) if first.get("type") == "user" else None + return prompt.lstrip() if isinstance(prompt, str) else "" + + def review_kind(given: dict[str, typing.Any]) -> ReviewKind | None: """What a launch reviews, a reviewer's pass, a comprehension seat or the security pass; None for any other subagent.""" if pass_reviewed := PASS_OF.get(text(given, "subagent_type")): @@ -56,12 +78,6 @@ 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") diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 6846c9ee..ac32aa7e 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -60,8 +60,8 @@ 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; and a Skill call there of `security-review` or `claude-security` from the session's own agent, which runs on the worker's rung", + "a reviewer, a comprehension seat or the security pass 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; and a `security-review` or `claude-security` Skill call in such a claude, which runs on its caller's rung, unless the caller is a subagent whose prompt opens with that sentence", overridable=False, ), # The cap holds with no ask, so no marker waives it. diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index e8c85265..36a804c7 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -19,7 +19,7 @@ from test_rank_todo import DECISIONS, README, TODO from test_env import isolated_env from model_routing import ladder from rule_hook.override_log import LogLine, parsed_entry, this_chunks -from rule_hook.reviewer_rung import reviewer_breaches +from rule_hook.reviewer_rung import reviewer_breaches, skill_breaches from rule_hook.git import git as rule_hook_git from model_routing.ladder import Rung from shell_command import segments, simple_commands @@ -315,21 +315,41 @@ 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"): + def skill_refused(self, given: dict, environ: dict[str, str] = ENVIRON, subagent_prompt: str | None = None) -> list[Breach]: + transcript = "" + if subagent_prompt is not None: + transcript = os.path.join(tempfile.mkdtemp(), "agent-a1.jsonl") + self.addCleanup(subprocess.run, ["rm", "-rf", os.path.dirname(transcript)]) + pathlib.Path(transcript).write_text(json.dumps({"type": "user", "message": {"role": "user", "content": subagent_prompt}}) + "\n") + return skill_breaches(Call("Skill", given, "/r", "general-purpose" if subagent_prompt is not None else "", transcript, subagent_prompt is not None), environ) + + def test_a_security_skill_from_the_sessions_own_agent_is_refused_below_the_projects_rung(self): + for skill in ("/security-review", "claude-security", "claude-security:claude-security", "security-review"): with self.subTest(skill=skill): - breaches = reviewer_breaches(Call("Skill", {"skill": skill}, "/r"), self.ENVIRON) + breaches = self.skill_refused({"skill": skill}) 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)), []) + self.assertEqual(rules(self.skill_refused({"skill": skill}, 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_a_security_skill_runs_on_its_callers_rung_whatever_model_its_input_names(self): + self.assertEqual(rules(self.skill_refused({"skill": "security-review", "model": "opus", "effort": "medium"})), ["reviewer-rung"]) - def test_any_other_skill_is_not_checked(self): - self.assertEqual(rules(reviewer_breaches(Call("Skill", {"skill": "simplify"}, "/r"), self.ENVIRON)), []) + def test_a_security_skill_passes_only_in_a_subagent_launched_as_the_security_pass(self): + self.assertEqual(rules(self.skill_refused({"skill": "security-review"}, self.ENVIRON, "You are the security pass for this chunk. Invoke /security-review.")), []) + self.assertEqual(rules(self.skill_refused({"skill": "security-review"}, self.ABOVE, "Invoke /security-review.")), ["reviewer-rung"], "a subagent's rung is unknown, whatever the worker's") + unreadable = skill_breaches(Call("Skill", {"skill": "security-review"}, "/r", "general-purpose", "/nonexistent/agent-a1.jsonl", True), self.ENVIRON) + self.assertEqual(rules(unreadable), ["reviewer-rung"]) + + def test_any_other_skill_or_a_claude_loop_claude_did_not_start_is_not_checked(self): + self.assertEqual(rules(self.skill_refused({"skill": "simplify"})), []) + self.assertEqual(rules(self.skill_refused({"skill": "security-review"}, {})), []) + + def test_a_session_started_with_an_agent_is_no_subagent(self): + hook_input = {"tool_name": "Skill", "tool_input": {"skill": "security-review"}, "cwd": "/r", "agent_type": "claude-security:claude-security", "transcript_path": "/t/s.jsonl"} + self.assertFalse(parsed_call(hook_input).subagent) + self.assertTrue(parsed_call({**hook_input, "agent_id": "a1"}).subagent) 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", {}) -- 2.52.0 From 9b4ddb1670b051cd96e4ae0d75e51a04ffac8f99 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 30 Oct 2026 13:22:25 +0100 Subject: [PATCH 4/5] =?UTF-8?q?Answer=20product-owner=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20answered=20?= =?UTF-8?q?by=20the=20stability=20round's=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From fa70eb2bfee1e7ed1cf512cc8539f83d3bc52154 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 30 Oct 2026 13:22:25 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20answered=20?= =?UTF-8?q?by=20the=20stability=20round's=20fix,=20with=20its=20?= =?UTF-8?q?=F0=9F=9F=A2s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0