diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cd05cc..51b352a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `rule-hook` now holds the files a `git commit` would commit to its file rules (`action-pin`, `image-pin`, `ignorefile-sorted`, `no-ai-attribution`), so a file a Bash command wrote is checked as an Edit or Write is. A `# rule-override` line in the file or the command still overrides a breach. +- `rule-hook` now checks files at `git commit`: each file that differs from HEAD or is untracked and not ignored, even one the commit leaves out. It holds each to `action-pin`, `image-pin`, `ignorefile-sorted` and `no-ai-attribution`, so a file a Bash command wrote is checked as an Edit or Write is. A `# rule-override` line in the file or the command overrides a breach. - `chunk-pr merge` now refuses while a scoring run the plan calls is unrecorded on the branch, and `larv-review needs-scoring-run` calls one after a release is cut with none. ## 0.7.0 diff --git a/bin/rule_hook/main.py b/bin/rule_hook/main.py index c029fb4a..b15401e5 100644 --- a/bin/rule_hook/main.py +++ b/bin/rule_hook/main.py @@ -8,17 +8,18 @@ subagent. The rules: {rules} -A file a Bash command writes, such as through `cat > Dockerfile`, is checked when a `git commit` would commit it, not -when written: the file rules (action-pin, image-pin, ignorefile-sorted, no-ai-attribution) hold each file that differs -from HEAD in the index or the work tree, or is untracked and not ignored, to the lines it adds. A `# rule-override` line -in that file or in the commit command overrides its breach. - A call overrides a rule with `# rule-override : `: - anywhere in a Bash command, such as a trailing comment - in a file, as a comment line in the text the edit writes - in Markdown, as `` +A file a Bash command writes, such as through `cat > Dockerfile`, is checked when a `git commit` runs, not when written. +The commit checks every file that differs from HEAD, in the index or the work tree, and every untracked file that is +not ignored, even one the commit leaves out. It holds each to the rules that name a file (action-pin, image-pin, +ignorefile-sorted, no-ai-attribution), judged on the lines the file adds. A marker among those lines, or in the commit +command, overrides the file's breach. + Each override that let a call through is appended to rule-overrides.tsv in the git directory of the checkout it touched: UTC time, branch, the commit checked out, rule, reason, and the file written or the command's first line. An override outside any git checkout is not logged. diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 0c68de8f..206b8fb1 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -104,7 +104,7 @@ class Breach: detail: str # The checkout whose log records an override of this breach. directory: str - # Text beyond the call's own whose markers override this breach: the file a commit holds, as an Edit's text is for its file. + # The lines a commit adds to the breach's file: its markers override this breach, as a Write's text overrides its own file's. marked: str = "" @@ -126,7 +126,7 @@ def overrides(written: str) -> tuple[dict[str, str], list[str]]: def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> Checked: granted, malformed = overrides(written) - # Each breach is overridden by the call's markers and by its own file's. + # A marker overrides a breach when it is in the call's own text or in the breach's file. grants = [granted | overrides(breach.marked)[0] for breach in breaches] blocking = [breach for breach, grant in zip(breaches, grants) if breach.rule not in grant] messages = [f"`{marker}` names no rule below, or gives no reason." for marker in malformed] if blocking else [] diff --git a/docs/decisions.md b/docs/decisions.md index 348261d0..b105d0a6 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -412,7 +412,7 @@ Valid while a model switch inside a session discards its prompt cache. ## rule-hook: a PreToolUse hook enforces each rule a program can check, a `# rule-override : ` marker overrides any rule but those `rule-hook --help` marks as taking none, and larv-review's overrides pass rules on each override before merge -2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; a commit also holds the files it would commit to the file rules, since a file a Bash command writes reaches no write check; that feedback comes later, at the commit. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. +2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; checking the staged diff at commit time would also cover files a Bash command writes, at the cost of later feedback. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering plan item 166: no marker overrides `reviewer-rung`. 2026-11-04, lilleman: the title points at `rule-hook --help`, which lists every rule no marker overrides from the code, so the title can't drift from it; the comment above each in `bin/rule_hook/rules.py` says why. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. 2026-11-11, lilleman: the hook also checks, at a `git commit`, each file the commit would commit against the rules that name a file, since a file a Bash command writes reaches no write check; the feedback comes at the commit, not at the write. ## rules/: `CLAUDE.md` holds the worker's rules that no file path can scope, and each topic's rules for the worker live in a `rules/` file that Claude Code loads by its `paths:` frontmatter