Answer principles round 1: 0 🔴, 6 🟡; derive the reviewers from agents/, open the security pass's prompt with a sentence, and type the review kinds
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
"""The routing ladder, and the rung an R + C picks from the project's rung: docs/decisions.md → `routing:`."""
|
||||
import dataclasses
|
||||
import re
|
||||
import typing
|
||||
|
||||
# How Rung.__str__ spells a rung that names an effort, and Rung.parse reads it back.
|
||||
WORDING = re.compile(r"(?P<model>\S+) at (?P<effort>\S+) effort")
|
||||
# What a review launch reviews: a reviewer, a comprehension seat or the security pass.
|
||||
ReviewKind = typing.Literal["reviewer", "seat", "security"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -31,7 +34,7 @@ class Rung:
|
||||
return Rung(model, effort)
|
||||
return Rung(family.model, effort) if effort else family
|
||||
|
||||
# The one spelling of a rung: the archive records it, loop-claude's environment carries it, and parse reads it back.
|
||||
# The one spelling of a rung; parse reads it back.
|
||||
def __str__(self) -> str:
|
||||
return f"{self.model} at {self.effort} effort" if self.effort else self.model
|
||||
|
||||
@@ -81,8 +84,8 @@ def stepped_up(rung: Rung) -> Rung:
|
||||
return climbed(rung, 1)
|
||||
|
||||
|
||||
def review_rung(kind: str, project: Rung, worker: Rung) -> Rung:
|
||||
"""The rung a review runs on, which loop-claude's worker prompt and rule-hook's refusal both hold it to: a reviewer on the higher of the worker's rung and the project's, anything else, a comprehension seat or the security pass, on the project's."""
|
||||
def review_rung(kind: ReviewKind, project: Rung, worker: Rung) -> Rung:
|
||||
"""The rung a review runs on: a reviewer on the higher of the worker's rung and the project's; a seat or the security pass on the project's."""
|
||||
return highest(project, worker) if kind == "reviewer" else project
|
||||
|
||||
|
||||
|
||||
@@ -5,34 +5,26 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from rule_hook.reviewer_rung import REVIEWERS, SEAT, SECURITY
|
||||
from rule_hook.reviewer_rung import REVIEWERS, SEAT, SECURITY_OPENER
|
||||
from repo_checks.test_python_floor import ROOT
|
||||
|
||||
OPENING = re.compile(r"^## Opening\n+```\n([^\n]+?\.)(?: |\n)", re.MULTILINE)
|
||||
SPELLING = re.compile(r"(?<![\w/])/[a-z][a-z-]+")
|
||||
|
||||
|
||||
def reviewer_column(row_name: str) -> str:
|
||||
"""The Reviewer cell of the row of larv-review's §3 table that opens with row_name."""
|
||||
rows = [line for line in (ROOT / "skills" / "larv-review" / "SKILL.md").read_text(encoding="utf-8").splitlines() if line.startswith(f"| {row_name} |")]
|
||||
assert len(rows) == 1, f"larv-review's §3 table has {len(rows)} rows named {row_name}"
|
||||
return rows[0].split("|")[2]
|
||||
REVIEWER_NAME = re.compile(r"\b[a-z]+(?:-[a-z]+)*-(?:reviewer|architect|auditor)\b")
|
||||
LARV_REVIEW = (ROOT / "skills" / "larv-review" / "SKILL.md").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
class ReviewerLaunches(unittest.TestCase):
|
||||
"""rule-hook holds a review launch to its rung by recognising it; these fail when what it recognises drifts from what the skills launch."""
|
||||
|
||||
def test_the_reviewer_types_are_the_agents_the_repo_defines(self):
|
||||
self.assertEqual(REVIEWERS, {path.stem for path in (ROOT / "agents").glob("*.md")})
|
||||
def test_the_reviewers_are_the_ones_larv_review_s_pass_table_names(self):
|
||||
passes = LARV_REVIEW.split("## 3. Passes", 1)[1].split("A comment is prose", 1)[0]
|
||||
self.assertEqual(set(REVIEWER_NAME.findall(passes)), REVIEWERS)
|
||||
|
||||
def test_the_seat_opening_is_the_sentence_that_opens_every_seat_prompt(self):
|
||||
opening = OPENING.search((ROOT / "skills" / "comprehension-panel" / "seat-prompts.md").read_text(encoding="utf-8"))
|
||||
self.assertIsNotNone(opening, "seat-prompts.md has a `## Opening` section whose code block opens with a sentence")
|
||||
self.assertEqual(SEAT, opening.group(1) if opening else "")
|
||||
|
||||
def test_the_security_pattern_matches_the_two_launches_larv_review_names(self):
|
||||
launched = {spelling for row in ("Security", "Full scan") for spelling in SPELLING.findall(reviewer_column(row))}
|
||||
self.assertEqual(launched, {"/security-review", "/claude-security"})
|
||||
self.assertEqual({alternative.removesuffix(r"\b") for alternative in SECURITY.pattern.split("|")}, launched)
|
||||
for spelling in launched:
|
||||
self.assertTrue(SECURITY.search(f"Invoke {spelling} over the branch diff."), spelling)
|
||||
def test_the_security_opening_is_the_sentence_larv_review_has_the_security_pass_open_with(self):
|
||||
security = LARV_REVIEW.split("### Security", 1)[1].split("### Overrides", 1)[0]
|
||||
self.assertIn(SECURITY_OPENER, security)
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
"""Hold each Agent call that launches a review to the rung loop-claude hands its worker: docs/decisions.md → `routing:`."""
|
||||
import re
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from rule_hook.rules import Breach
|
||||
from rule_hook.call import Call, text
|
||||
from model_routing.worker_rungs import handed
|
||||
from model_routing.ladder import position, review_rung, Rung
|
||||
from model_routing.ladder import position, review_rung, ReviewKind, Rung
|
||||
|
||||
# larv-review §3's reviewers, by the subagent type its passes launch.
|
||||
REVIEWERS = frozenset(("override-reviewer", "principles-auditor", "product-owner-reviewer", "prose-reviewer", "stability-reviewer", "systems-architect"))
|
||||
# A reviewer is an agent under agents/, as CLAUDE.md → "Vocabulary" defines it.
|
||||
REVIEWERS = frozenset(path.stem for path in (pathlib.Path(__file__).resolve().parents[2] / "agents").glob("*.md"))
|
||||
# The opening of every comprehension seat's prompt: skills/comprehension-panel/seat-prompts.md → "Opening".
|
||||
SEAT = "You are one seat of a comprehension panel."
|
||||
# The security pass's subagent invokes one of these skills.
|
||||
SECURITY = re.compile(r"/security-review\b|/claude-security\b")
|
||||
# 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 = {"seat": "a comprehension seat", "security": "the security pass's subagent"}
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ def reviewer_breaches(call: Call, environ: typing.Mapping[str, str]) -> list[Bre
|
||||
return [Breach("reviewer-rung", f"{subject} would run on {named}, below {required}: launch it with {required.agent_args()}", call.cwd)]
|
||||
|
||||
|
||||
def review_kind(given: dict[str, typing.Any]) -> str | None:
|
||||
def review_kind(given: dict[str, typing.Any]) -> ReviewKind | None:
|
||||
"""What a launch reviews, a reviewer, a comprehension seat or the security pass; None for any other subagent."""
|
||||
if text(given, "subagent_type") in REVIEWERS:
|
||||
return "reviewer"
|
||||
prompt = text(given, "prompt")
|
||||
if SEAT in prompt:
|
||||
return "seat"
|
||||
if SECURITY.search(prompt):
|
||||
if SECURITY_OPENER in prompt:
|
||||
return "security"
|
||||
return None
|
||||
|
||||
|
||||
@@ -177,7 +177,9 @@ class ReviewerRung(unittest.TestCase):
|
||||
def test_a_reviewer_below_the_project_rung_is_refused_naming_the_arguments_to_pass(self):
|
||||
breaches = reviewer_breaches(Call("Agent", {"subagent_type": "stability-reviewer", "model": "sonnet", "effort": "high", "prompt": "Review."}, "/r"), self.ENVIRON)
|
||||
self.assertEqual(rules(breaches), ["reviewer-rung"])
|
||||
self.assertEqual(breaches[0].detail, "stability-reviewer would run on claude-sonnet-5-5 at high effort, below claude-opus-5-5 at medium effort: launch it with model opus, effort medium")
|
||||
self.assertIn("stability-reviewer", breaches[0].detail)
|
||||
self.assertIn("claude-sonnet-5-5 at high effort", breaches[0].detail)
|
||||
self.assertIn("model opus, effort medium", breaches[0].detail)
|
||||
|
||||
def test_a_reviewer_on_the_project_rung_or_a_rerun_above_it_passes(self):
|
||||
self.assertEqual(self.refused({"subagent_type": "prose-reviewer", "model": "opus", "effort": "medium"}), [])
|
||||
@@ -205,8 +207,8 @@ class ReviewerRung(unittest.TestCase):
|
||||
def test_a_seat_or_a_security_launch_is_held_to_the_project_rung_alone(self):
|
||||
seat = {"prompt": "You are one seat of a comprehension panel. Tools: Read, Grep, Glob.", "model": "opus", "effort": "medium"}
|
||||
self.assertEqual(self.refused(seat, self.ABOVE), [])
|
||||
self.assertEqual(self.refused({"prompt": "Invoke /security-review over the branch diff.", "model": "sonnet", "effort": "high"}), ["reviewer-rung"])
|
||||
self.assertEqual(self.refused({"prompt": "Run /claude-security scan this branch's changes at high.", "model": "opus", "effort": "medium"}), [])
|
||||
self.assertEqual(self.refused({"prompt": "You are the security pass for this chunk. Invoke /security-review over the branch diff.", "model": "sonnet", "effort": "high"}), ["reviewer-rung"])
|
||||
self.assertEqual(self.refused({"prompt": "You are the security pass for this chunk. Run /claude-security scan this branch's changes at high.", "model": "opus", "effort": "medium"}), [])
|
||||
|
||||
def test_a_seat_named_below_the_project_rung_is_refused(self):
|
||||
self.assertEqual(self.refused({"prompt": "You are one seat of a comprehension panel.", "model": "sonnet", "effort": "high"}), ["reviewer-rung"])
|
||||
@@ -214,6 +216,7 @@ class ReviewerRung(unittest.TestCase):
|
||||
def test_any_other_subagent_keeps_its_own_routing(self):
|
||||
self.assertEqual(self.refused({"subagent_type": "Explore", "model": "haiku", "effort": "low", "prompt": "Find the callers of run_worker."}), [])
|
||||
self.assertEqual(self.refused({"prompt": "Note that security-review runs in CI.", "model": "haiku", "effort": "low"}), [])
|
||||
self.assertEqual(self.refused({"prompt": "Find where /security-review is named.", "model": "haiku", "effort": "low"}), [], "a mention without the opening sentence is no launch")
|
||||
|
||||
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"}, {}), [])
|
||||
@@ -283,7 +286,10 @@ class Hook(unittest.TestCase):
|
||||
call = {"cwd": self.repo, "tool_input": {"subagent_type": "stability-reviewer", "model": "sonnet", "effort": "high", "prompt": "Review. # rule-override reviewer-rung: trust me"}, "tool_name": "Agent"}
|
||||
ran = hook(call, self.repo, ReviewerRung.ENVIRON)
|
||||
self.assertEqual(ran.returncode, 2)
|
||||
self.assertIn("Blocked by rule reviewer-rung: stability-reviewer would run on claude-sonnet-5-5 at high effort", ran.stderr)
|
||||
self.assertIn("Blocked by rule reviewer-rung", ran.stderr)
|
||||
self.assertIn("stability-reviewer", ran.stderr)
|
||||
self.assertIn("claude-sonnet-5-5 at high effort", ran.stderr)
|
||||
self.assertIn("model opus, effort medium", ran.stderr)
|
||||
self.assertNotIn("rule-override", ran.stderr)
|
||||
|
||||
def test_an_agent_call_at_its_rung_passes(self):
|
||||
|
||||
Reference in New Issue
Block a user