Answer principles round 1: 0 🔴, 5 🟡; enforce run-heavy in rule-hook, take slots through one tested function, exit 125 on lock errors, fake meminfo in black-box tests

This commit is contained in:
2026-10-23 10:55:55 +02:00
parent 6725ee4c9d
commit c7dbd56f39
14 changed files with 136 additions and 59 deletions
+23 -1
View File
@@ -8,7 +8,7 @@ from git_command import commits
from review_folder import REPORTS
from shell_command import Simple
RuleName = typing.Literal["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "todo-rank-check"]
RuleName = typing.Literal["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"]
@dataclasses.dataclass(frozen=True)
@@ -60,6 +60,10 @@ RULES: dict[RuleName, Rule] = {
"a larv-review round's commit title gives the counts of 🔴 and 🟡 findings the round reported, such as `Answer stability round 1: 1 🔴, 2 🟡; flag a deleted test`, since score-outcomes counts them",
"a git commit whose message opens `Answer <pass> round <n>:`",
),
"run-heavy": Rule(
"a heavy command, which loads the machine for minutes, runs under ~/.claude/bin/run-heavy, so sessions running at once cannot starve the machine",
"a docker build, docker buildx build or docker compose build, and a run of mutmut, cargo mutants, Stryker or Infection, the mutation tools stability-reviewer names; a gate script it cannot tell from a light one",
),
"todo-rank-check": Rule(
"while todo.md has changes, staged or not, a git commit waits until ~/.claude/bin/rank_todo.py --check passes on it",
"a git commit in a checkout whose todo.md has changes",
@@ -95,6 +99,21 @@ class Outcome:
overridden: list[tuple[Breach, str]]
# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run.
LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "time", "uvx", "yarn"})
# Each heavy tool, and the words of which one must follow it within two words for its call to be heavy; an empty set makes every call heavy.
HEAVY = {"cargo": {"mutants"}, "docker": {"build"}, "infection": set(), "mutmut": {"run"}, "stryker": {"run"}}
def heavy(words: list[str]) -> bool:
"""Whether the simple command runs a heavy tool, itself or through a launcher, outside run-heavy."""
names = [re.sub(r"[^A-Za-z_-].*", "", posixpath.basename(word)) for word in words]
if names[0] == "run-heavy":
return False
at = range(len(names)) if names[0] in LAUNCHERS else range(1)
return any(names[i] in HEAVY and (not HEAVY[names[i]] or HEAVY[names[i]] & set(names[i + 1:i + 3])) for i in at)
def overrides(written: str) -> tuple[dict[str, str], list[str]]:
"""The rules the text overrides with their reasons, and the markers that name no rule or give no reason; a marker for a rule that takes no override is neither."""
given = [(rule, reason.strip().removesuffix("-->").strip()) for rule, reason in OVERRIDE.findall(written)]
@@ -123,6 +142,9 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre
publishing = [simple for simple in simples if simple.words[0] in ("gh", "git", "tea")]
if publishing and ATTRIBUTION.search(command):
breaches.append(Breach("no-ai-attribution", "the command carries an attribution", publishing[0].directory))
for simple in simples:
if heavy(simple.words):
breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words[:3])}` as `~/.claude/bin/run-heavy {' '.join(simple.words[:2])} …`, in the background", simple.directory))
for commit in found:
if commit.from_file:
breaches.append(Breach("commit-one-line", "pass the message as one -m '<line>', not from a file", commit.directory))