Merge remote-tracking branch 'origin/main' into patch-0.10.1

# Conflicts:
#	CHANGELOG.md
#	README.md
#	bin/loop_claude/loop/chunk_start.py
#	bin/loop_claude/loop/close.py
#	bin/loop_claude/loop/main.py
#	bin/loop_claude/routing.py
#	bin/loop_claude/test_loop_claude.py
#	bin/project_config/main.py
#	bin/project_config/test_project_config.py
#	docs/decisions.md
This commit is contained in:
2026-11-15 19:54:42 +01:00
183 changed files with 9061 additions and 3308 deletions
+34 -8
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, Skill and Write call, in every session and
settings.json runs it before each Agent, Bash, Edit, Grep, MultiEdit, Read, Skill and Write call, in every session and
subagent. The rules:
{rules}
@@ -33,6 +33,7 @@ override cannot be logged; 0 otherwise. `rule-hook overrides` exits 1 when git c
checkout or the branch's reflog. Exit 1, a non-blocking error to Claude Code, on input it
cannot read.
"""
import functools
import json
import os
import pathlib
@@ -41,17 +42,23 @@ import time
import typing
from rule_hook.call import applied, Call, FILE_TOOLS, parsed_call, text
from rule_hook.rules import Breach, check, Checked, command_breaches, file_breaches, rules_help
from git_cli.git_command import commits
from rule_hook.rules import Breach, check, Checked, command_breaches, file_breaches, rules_help, title_breaches
from git_cli.git_command import CommitCall, commits
from rule_hook.committed_files import committed_file_breaches
from rule_hook.env_file import env_file_breaches
from failure import Failure
from git_cli.git_repo import git
from rule_hook.git import guarded_git
from project_config.main import located
from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override
from project_config.settings import ProjectConfig, Unnamed
from rule_hook.file_text import read
from rule_hook.repeat_read import read_breaches
from rule_hook.reviewer_report import report_breaches
from rule_hook.reviewer_rung import reviewer_breaches, skill_breaches
from rule_hook.round_cap import round_cap_breaches
from command_lines.shell_command import simple_commands
from project_config import templates
from rule_hook.todo_check import todo_breaches
@@ -86,9 +93,12 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
return text(call.given, "args"), text(call.given, "skill"), skill_breaches(call, environ, home)
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)
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + read_breaches(call, home) + env_file_breaches(call, home)
if call.tool == "Read":
return "", text(call.given, "file_path"), read_breaches(call, home)
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home)
if call.tool == "Grep":
# Only env-file-read checks a Grep, and it takes no override, so no marker or log line concerns the call.
return "", "", env_file_breaches(call, home)
path = text(call.given, "file_path")
if call.tool not in FILE_TOOLS or not path:
return None
@@ -115,9 +125,25 @@ def answer(checked: Checked, what: str, now: float) -> int:
def bash_breaches(command: str, cwd: str, home: str) -> list[Breach]:
"""The breaches of the command's own words, then of each commit it makes, then of the files those commits may take."""
simples = simple_commands(command, cwd, home)
found = commits(simples, home)
in_commits = [breach for commit in found for breach in commit_breaches(commit, pathlib.Path(home))]
in_files = [breach for directory in dict.fromkeys(commit.directory for commit in found) for breach in committed_file_breaches(directory)]
round_cap = [breach for commit in found for breach in round_cap_breaches(commit)]
todo = [breach for commit in found for breach in todo_breaches(commit.directory, pathlib.Path(home))]
return command_breaches(command, simples, home) + round_cap + todo + in_files
return command_breaches(command, simples) + in_commits + in_files
def commit_breaches(commit: CommitCall, home: pathlib.Path) -> list[Breach]:
"""The breaches of one commit: its title's and its round's, read through the title templates of the project's config, and its plan's. A config that cannot be read is a breach itself, since no title can then be checked."""
config = located(commit.directory, home, functools.partial(git, guarded=True))
unread = []
if isinstance(config, Failure) and not isinstance(config, Unnamed):
unread = [Breach("commit-title", f"the project's config cannot be read, so the title is not checked against its template: {config.reason}", commit.directory)]
titles = config.titles if isinstance(config, ProjectConfig) else templates.BARE
return unread + title_breaches(commit, titles, isinstance(config, ProjectConfig) and on_item_branch(commit.directory, config.branch)) + round_cap_breaches(commit, titles) + todo_breaches(commit.directory, home)
def on_item_branch(directory: str, template: str) -> bool:
"""Whether directory's checkout is on a branch that fits template, the config's `branch`: a plan item's branch, whose commits carry the item's ID. Any other branch, such as a release review's, has no item to give {id}."""
branch = guarded_git(directory, "symbolic-ref", "--quiet", "--short", "HEAD")
return not isinstance(branch, Failure) and templates.branch_fits(template, branch)