Answer stability round 2: keep the line break that ends a heredoc, read a run of separators as one, check every untagged compose image, and reject a non-object tool input
This commit is contained in:
+19
-11
@@ -14,14 +14,18 @@ subagent. The rules:
|
||||
`container:`, names a full patch version, a date stamp or a digest
|
||||
no-ai-attribution no Claude or Anthropic co-author or generated-with line, in a file written or
|
||||
in a git, gh or tea command
|
||||
todo-rank-check a commit that stages todo.md, or commits with -a while todo.md has changes,
|
||||
needs rank_todo.py --check to pass on it
|
||||
todo-rank-check a git commit while todo.md has changes, staged or not, needs
|
||||
rank_todo.py --check to pass on it
|
||||
|
||||
The file rules see what an Edit, MultiEdit or Write call writes, not a file a Bash command writes.
|
||||
|
||||
A call overrides a rule with `# rule-override <rule>: <reason>`: anywhere in a Bash command, such as
|
||||
a trailing comment; in a file, as a comment line in the text the edit writes. Each override that
|
||||
let a call through is appended to rule-overrides.tsv in the checkout's git directory: UTC time,
|
||||
branch, rule, reason, and the file written or the command's first line. `rule-hook overrides`
|
||||
prints the lines for the current branch.
|
||||
a trailing comment; in a file, as a comment line in the text the edit writes, or in Markdown as
|
||||
`<!-- rule-override <rule>: <reason> -->`. Each override that let a call through is appended to
|
||||
rule-overrides.tsv in the checkout's git directory: UTC time, branch, rule, reason, and the file
|
||||
written or the command's first line. `rule-hook overrides` prints the lines for the current branch.
|
||||
|
||||
Run with no arguments in a terminal, it prints this help.
|
||||
|
||||
Exit 2 with the rule, why it holds and how to override it, when a rule blocks the call; 0 otherwise.
|
||||
Exit 1, a non-blocking error to Claude Code, on input it cannot read.
|
||||
@@ -42,7 +46,7 @@ LOG = "rule-overrides.tsv"
|
||||
|
||||
|
||||
def main(argv: list[str], stdin: str) -> int:
|
||||
if argv in (["-h"], ["--help"]):
|
||||
if argv in (["-h"], ["--help"]) or not argv and not stdin:
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
if argv == ["overrides"]:
|
||||
@@ -53,6 +57,8 @@ def main(argv: list[str], stdin: str) -> int:
|
||||
try:
|
||||
call = json.loads(stdin)
|
||||
tool, given, cwd = call["tool_name"], call["tool_input"], call["cwd"]
|
||||
if not isinstance(given, dict):
|
||||
raise TypeError("tool_input is no object")
|
||||
except (json.JSONDecodeError, KeyError, TypeError) as failure:
|
||||
print(f"rule-hook cannot read the hook input: {failure}", file=sys.stderr)
|
||||
return 1
|
||||
@@ -69,6 +75,8 @@ def main(argv: list[str], stdin: str) -> int:
|
||||
if not blocking:
|
||||
return 0
|
||||
where = "the command" if tool == "Bash" else "the text you write, as a comment line"
|
||||
if "rule-override" in text and not granted:
|
||||
print("The rule-override in this call names no rule below, or gives no reason.", file=sys.stderr)
|
||||
for rule in sorted({breach.rule for breach in blocking}):
|
||||
details = "; ".join(breach.detail for breach in blocking if breach.rule == rule)
|
||||
print(f"Blocked by rule {rule}: {details}. The rule: {RULES[rule]}. Where it does not fit this case, add `# rule-override {rule}: <reason>` to {where}; larv-review's judge rules on the reason.", file=sys.stderr)
|
||||
@@ -79,7 +87,7 @@ def checked_call(tool: str, given: dict[str, typing.Any], cwd: str) -> tuple[str
|
||||
"""The text that may carry an override, the directory whose checkout logs it, and the call's breaches."""
|
||||
if tool == "Bash":
|
||||
command = str(given.get("command") or "")
|
||||
todo = [breach for commit in commits(command, cwd) for breach in todo_breaches(commit.directory, commit.all)]
|
||||
todo = [breach for commit in commits(command, cwd) for breach in todo_breaches(commit.directory)]
|
||||
return command, cwd, command_breaches(command, cwd) + todo
|
||||
path = str(given.get("file_path") or "")
|
||||
if tool not in ("Edit", "MultiEdit", "Write") or not path:
|
||||
@@ -97,12 +105,12 @@ def checked_call(tool: str, given: dict[str, typing.Any], cwd: str) -> tuple[str
|
||||
return added, os.path.dirname(path), file_breaches(path, before, added, after)
|
||||
|
||||
|
||||
def todo_breaches(directory: str, staged_all: bool) -> list[Breach]:
|
||||
def todo_breaches(directory: str) -> list[Breach]:
|
||||
top = git(directory, "rev-parse", "--show-toplevel")
|
||||
if not top or not (pathlib.Path(top) / "todo.md").is_file():
|
||||
return []
|
||||
changed = git(top, "diff", "--cached", "--name-only", "--", "todo.md") or (staged_all and git(top, "diff", "--name-only", "--", "todo.md"))
|
||||
if not changed:
|
||||
# Any change, staged or not: the hook runs before a `git add` earlier in the same command.
|
||||
if not git(top, "status", "--porcelain", "--", "todo.md"):
|
||||
return []
|
||||
return [Breach("todo-rank-check", line) for line in rank_todo.check_failures(pathlib.Path(top) / "todo.md")]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user