From 14c8e7f0129bdd42a686bdd3e0b15ad5a38660cd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:17:42 +0200 Subject: [PATCH 01/20] Grant the bench's runs only the tools a review needs, in place of skipping every permission --- CHANGELOG.md | 1 + todo.md | 5 ----- workflow-bench/bench.py | 18 ++++++++++++++++-- workflow-bench/run-prompt.md | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a18df30d..d8233692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- The bench's runs, `workflow-bench/bench.py`, no longer skip permissions: each run gets `Agent`, `Skill(security-review)`, `git`, edits to its clone and report, and reads of its clone, its version's copy and `~/.claude/agents/`, and is denied the rest, `~/.claude/.credentials.json` and any other shell command included. A review that needs to run a project's code or tests now has no way to; `workflow-bench/run-prompt.md` says so. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/todo.md b/todo.md index ec6481f7..647ee8d6 100644 --- a/todo.md +++ b/todo.md @@ -12,7 +12,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 50 | 0.2.0 | | principle | **Grant the bench's runs only the tools a review needs, in place of skipping every permission.** | 2 | 2 | 1 | 3 | 2 | 1.1 by 3 | 5.5 | | 65 | 0.2.0 | | defect | **Archive each judge reply the loop rejects.** | 2 | 1 | 3 | 4 | 4 | 3 by 3 | 5.5 | | 153 | 0.2.0 | | decision | **Route the judge and the reviewers on the highest E + I in their chunk, an item the worker takes in included.** | 3 | 1 | 3 | 5 | 4 | 1.2 by 5 | 3.0 | | 161 | 0.2.0 | | | **Have loop-claude run a preflight script before each fresh worker and put its findings in the worker's prompt, so the worker no longer spends tool calls finding the chunk's mechanical facts.** | 4 | 2 | 3 | 7 | 6 | 1.1 by 4, 1.4 by 6, 1.5 by 6 | 2.9 | @@ -84,10 +83,6 @@ ## Details -### 50. Grant the bench's runs only the tools a review needs, in place of skipping every permission. - -"Always grant explicit access to data", in `principles/technical-principles.md`: `workflow-bench/bench.py` starts claude with `--dangerously-skip-permissions`, and no rule confines it to a sandbox, so a run on the host reaches the host's credentials and other checkouts. - ### 65. Archive each judge reply the loop rejects. A defect: goal 3, keeping unattended runs' transcripts backed up, does not hold while a rejected judge reply reaches only stderr. Raised by the principles audit of PR #215: the judge runs with `--no-session-persistence`, so the archive cannot answer the 3am question of why the loop rejected a verdict. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index 25ab0920..e4b34329 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -33,6 +33,17 @@ CASES = { ATTEMPTS = 4 +def allowed_tools(clone, version_dir, report): + """The tools a review needs and the paths each reaches; anything else is denied, not asked.""" + agents = pathlib.Path.home() / ".claude" / "agents" + # A rule names an absolute path as "//", and "/**" takes a whole tree. + reads = [f"/{root}/**" for root in (clone, version_dir, agents)] + return [ + "Agent", "Skill(security-review)", "Bash(git *)", f"Edit(/{clone}/**)", f"Edit(/{report})", + *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in reads), + ] + + def git(repo, *args): return subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True, text=True).stdout.strip() @@ -73,13 +84,16 @@ def run(name): if report.exists(): return f"{name}: done" base, head = fresh_clone(case, clone) + version_dir = BENCH / "versions" / version prompt = (BENCH / "run-prompt.md").read_text().format( - version_dir=BENCH / "versions" / version, base=base, head=head, case=case, report=report) + version_dir=version_dir, base=base, head=head, case=case, report=report) log = BENCH / "logs" / f"{name}.{attempt}.jsonl" log.parent.mkdir(exist_ok=True) with log.open("w") as out: subprocess.run( - ["claude", "-p", prompt, "--dangerously-skip-permissions", "--model", "claude-opus-5-5", "--output-format", "stream-json", "--verbose"], + ["claude", "-p", prompt, "--permission-mode", "dontAsk", "--permission-prompts", "none", + "--allowedTools", *allowed_tools(clone, version_dir, report), + "--model", "claude-opus-5-5", "--output-format", "stream-json", "--verbose"], cwd=clone, stdout=out, stderr=subprocess.STDOUT) if report.exists(): return f"{name}: done on attempt {attempt}" diff --git a/workflow-bench/run-prompt.md b/workflow-bench/run-prompt.md index ecbf7e1b..a8365ad7 100644 --- a/workflow-bench/run-prompt.md +++ b/workflow-bench/run-prompt.md @@ -15,7 +15,7 @@ Report: write it to `{report}`. - Launch every agent in the foreground (`run_in_background: false`): background agents die when this headless turn ends. - No remote and no forge: skip the PR, CI, the external auto-reviewer and the merge; review locally. -- Do not run the repo's test suites. A targeted probe is fine, in the repo's own container tooling. +- Do not run the repo's code or test suites: the shell is limited to git. - Skip the comprehension check; say so in the report. - No human is reachable. Where the process names a no-human branch, take it; where it names none, take your recommendation and list the question in the report. - Commit each round's fixes on `chunk`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. -- 2.52.0 From a80bb6cc66c7c7092c149a2a0ba4751755734fec Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:18:24 +0200 Subject: [PATCH 02/20] Append the chunk's reading cost and refresh the plan item that tracks its rise --- docs/reading-cost.md | 17 +++++++++++++++++ todo.md | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index aca48ede..bd07ab08 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -537,3 +537,20 @@ Read most (opens and searches): - `README.md` 3 - `bin/loop_claude/loop/main.py` 3 - `bin/rank_todo.py` 3 + +## Reading cost, chunk 3a8a02906476, finished 2026-10-16T18:12:40Z + +107338 new input tokens before the first commit. + +Read most (opens and searches): + +- `todo.md` 6 +- `AGENTS.md` 3 +- `README.md` 3 +- `bin/todo_table.py` 3 +- `docs/scoring-and-goals-research.md` 3 +- `CHANGELOG.md` 2 +- `bin/git_repo.py` 2 +- `bin/markdown_text.py` 2 +- `bin/repo_checks/test_import_order.py` 2 +- `bin/score_outcomes/test_score_outcomes.py` 2 diff --git a/todo.md b/todo.md index 647ee8d6..8d8f7573 100644 --- a/todo.md +++ b/todo.md @@ -360,7 +360,7 @@ While `rank_todo.py` ranks two shapes, projects follow two sets of scoring rules ### 155. Lower the reading cost of the files a chunk reads most before its first commit. -`bin/reading-cost` on 2026-10-16: the last 5 chunks' median is 213946 new input tokens before their first commit, the 5 before them 133254. Read most over the last 5, by opens and searches: `todo.md` 61, `bin/test_rank_todo.py` 14, `docs/decisions.md` 14, `README.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `CHANGELOG.md` 10, `AGENTS.md` 7, `bin/rank_todo.py` 7, `bin/todo_table.py` 7, `agents/stability-reviewer.md` 6. The chunk that ships this item runs `bin/reading-cost --reset`. +`bin/reading-cost` on 2026-10-16: the last 5 chunks' median is 213946 new input tokens before their first commit, the 5 before them 139738. Read most over the last 5, by opens and searches: `todo.md` 58, `README.md` 13, `CHANGELOG.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `docs/decisions.md` 11, `AGENTS.md` 10, `bin/todo_table.py` 7, `agents/stability-reviewer.md` 6, `bin/loop_claude/cycle/judge.py` 5, `bin/rule_hook/test_rule_hook.py` 5. The chunk that ships this item runs `bin/reading-cost --reset`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. -- 2.52.0 From 58252f8948c2a78af6b18ce9dacf4d03af3e4afc Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:24:02 +0200 Subject: [PATCH 03/20] =?UTF-8?q?Answer=20security=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20allow=20only=20the=20git=20?= =?UTF-8?q?commands=20a=20review=20needs,=20deny=20the=20options=20that=20?= =?UTF-8?q?name=20a=20path,=20and=20load=20no=20user=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- todo.md | 4 +++- workflow-bench/bench.py | 25 +++++++++++++++---------- workflow-bench/run-prompt.md | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8233692..a8f25d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- The bench's runs, `workflow-bench/bench.py`, no longer skip permissions: each run gets `Agent`, `Skill(security-review)`, `git`, edits to its clone and report, and reads of its clone, its version's copy and `~/.claude/agents/`, and is denied the rest, `~/.claude/.credentials.json` and any other shell command included. A review that needs to run a project's code or tests now has no way to; `workflow-bench/run-prompt.md` says so. +- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/`) and its report, read its clone and the copy of `~/.claude` it benches, and run `git log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m`, without options that name a path git reads or writes. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/todo.md b/todo.md index 8d8f7573..d6c3c538 100644 --- a/todo.md +++ b/todo.md @@ -332,6 +332,8 @@ The maintainability senior and the inherited architect of PR #257's scoring run "Most, if not all, code should have automated tests", in `principles/technical-principles.md`: `compare.blind()` keeps the comparison blind, and a version name it misses invalidates the bench silently. +The tests also cover `workflow-bench/bench.py`'s `permission_flags`, with a probe: a headless claude given its flags is denied a read of a file outside the granted trees, a `git -c alias.x=… x` and a `git diff --no-index`, and is allowed the review's own git commands. + ### 4. Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran. Today the folder is the SHA-256 of the transcript's first timestamped line, which tells the human nothing; that line carries the start time. Drop the fallback to the first line, which every chunk of a project shares, and give the tests' fake transcripts ISO timestamps. `bin/reading-cost` takes a chunk's id from the folder's first 12 characters and skips a chunk whose id `docs/reading-cost.md` holds, so give it a way to match a figure written under the old name. @@ -360,7 +362,7 @@ While `rank_todo.py` ranks two shapes, projects follow two sets of scoring rules ### 155. Lower the reading cost of the files a chunk reads most before its first commit. -`bin/reading-cost` on 2026-10-16: the last 5 chunks' median is 213946 new input tokens before their first commit, the 5 before them 139738. Read most over the last 5, by opens and searches: `todo.md` 58, `README.md` 13, `CHANGELOG.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `docs/decisions.md` 11, `AGENTS.md` 10, `bin/todo_table.py` 7, `agents/stability-reviewer.md` 6, `bin/loop_claude/cycle/judge.py` 5, `bin/rule_hook/test_rule_hook.py` 5. The chunk that ships this item runs `bin/reading-cost --reset`. +`bin/reading-cost` on 2026-10-16: the median of the last 5 chunks is 213,946 new input tokens before their first commit, up from 139,738 for the 5 before them. Read most over the last 5, by opens and searches: `todo.md` 58, `README.md` 13, `CHANGELOG.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `docs/decisions.md` 11, `AGENTS.md` 10, `bin/todo_table.py` 7, `agents/stability-reviewer.md` 6, `bin/loop_claude/cycle/judge.py` 5, `bin/rule_hook/test_rule_hook.py` 5. The chunk that ships this item runs `bin/reading-cost --reset`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index e4b34329..e792dcc4 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -33,15 +33,21 @@ CASES = { ATTEMPTS = 4 -def allowed_tools(clone, version_dir, report): - """The tools a review needs and the paths each reaches; anything else is denied, not asked.""" - agents = pathlib.Path.home() / ".claude" / "agents" - # A rule names an absolute path as "//", and "/**" takes a whole tree. - reads = [f"/{root}/**" for root in (clone, version_dir, agents)] - return [ - "Agent", "Skill(security-review)", "Bash(git *)", f"Edit(/{clone}/**)", f"Edit(/{report})", - *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in reads), +def permission_flags(clone, version_dir, report): + """The tools a review needs, each limited to what it may touch; the run denies every other call.""" + # A permission rule writes an absolute path as "//"; a trailing "/**" matches everything under it. + trees = (f"/{clone}/**", f"/{version_dir}/**") + git = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am") + allowed = [ + "Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})", + *(f"Bash(git {command} *)" for command in git), + *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] + # git reads or writes any path through these options, and runs any command through a hook or config. + denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git * {option}*)" for option in ("--no-index", "--output", "-F", "--file", "-t", "--template"))] + # Only the clone's own settings: the user's add every checkout under ~/code to the readable trees. + return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", + "--allowedTools", *allowed, "--disallowedTools", *denied] def git(repo, *args): @@ -91,8 +97,7 @@ def run(name): log.parent.mkdir(exist_ok=True) with log.open("w") as out: subprocess.run( - ["claude", "-p", prompt, "--permission-mode", "dontAsk", "--permission-prompts", "none", - "--allowedTools", *allowed_tools(clone, version_dir, report), + ["claude", "-p", prompt, *permission_flags(clone, version_dir, report), "--model", "claude-opus-5-5", "--output-format", "stream-json", "--verbose"], cwd=clone, stdout=out, stderr=subprocess.STDOUT) if report.exists(): diff --git a/workflow-bench/run-prompt.md b/workflow-bench/run-prompt.md index a8365ad7..27ef4f27 100644 --- a/workflow-bench/run-prompt.md +++ b/workflow-bench/run-prompt.md @@ -15,7 +15,7 @@ Report: write it to `{report}`. - Launch every agent in the foreground (`run_in_background: false`): background agents die when this headless turn ends. - No remote and no forge: skip the PR, CI, the external auto-reviewer and the merge; review locally. -- Do not run the repo's code or test suites: the shell is limited to git. +- The shell runs only git, so run no code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities. - Skip the comprehension check; say so in the report. - No human is reachable. Where the process names a no-human branch, take it; where it names none, take your recommendation and list the question in the report. - Commit each round's fixes on `chunk`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. -- 2.52.0 From 40201803aea9e40b6f4e1e0406f1235cd9a29f01 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:24:02 +0200 Subject: [PATCH 04/20] =?UTF-8?q?Answer=20principles=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20git=20grant=20is=20na?= =?UTF-8?q?rrowed=20as=20the=20security=20round=20did,=20and=20the=20agent?= =?UTF-8?q?s=20grant=20is=20dropped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From ed4689872dd42bf29fd576816cc1aa14c2139ebb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:24:02 +0200 Subject: [PATCH 05/20] =?UTF-8?q?Answer=20stability=20round=201:=202=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20the=20git=20grant,=20the=20?= =?UTF-8?q?user=20settings=20and=20the=20agents=20grant=20are=20answered?= =?UTF-8?q?=20in=20the=20security=20round's=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 8ab8c09c89e26c0354e54bad9a7664579c89216e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:24:02 +0200 Subject: [PATCH 06/20] =?UTF-8?q?Answer=20prose=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1;=20the=20changelog=20states=20?= =?UTF-8?q?what=20holds,=20the=20bench=20rule=20says=20what=20to=20do=20in?= =?UTF-8?q?stead,=20and=20the=20docstring=20and=20comment=20are=20reworded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 95aa2b34779d4076d2005d56e0a280f5d649bad8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:32:36 +0200 Subject: [PATCH 07/20] =?UTF-8?q?Answer=20security=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20deny=20a=20git=20argument?= =?UTF-8?q?=20that=20names=20a=20path=20outside=20the=20clone,=20in=20plac?= =?UTF-8?q?e=20of=20listing=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- workflow-bench/bench.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f25d38..a8152ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/`) and its report, read its clone and the copy of `~/.claude` it benches, and run `git log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m`, without options that name a path git reads or writes. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. +- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/`) and its report, read its clone and the copy of `~/.claude` it benches, and run `git log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` (also as `-am` or `-a -m`). A git argument that names a path outside the clone is denied: an absolute path, one from `~`, one through `..` or one through a shell variable. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index e792dcc4..4f656d33 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -37,14 +37,17 @@ def permission_flags(clone, version_dir, report): """The tools a review needs, each limited to what it may touch; the run denies every other call.""" # A permission rule writes an absolute path as "//"; a trailing "/**" matches everything under it. trees = (f"/{clone}/**", f"/{version_dir}/**") - git = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am") + commands = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am", "commit -a -m") allowed = [ "Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})", - *(f"Bash(git {command} *)" for command in git), + *(f"Bash(git {command} *)" for command in commands), *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] - # git reads or writes any path through these options, and runs any command through a hook or config. - denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git * {option}*)" for option in ("--no-index", "--output", "-F", "--file", "-t", "--template"))] + # git reaches a path outside the clone only through an argument that names one: absolute, from ~, up + # through "..", through a variable, or glued to -O or -X. With -m, git refuses -F and ignores -t + # before reading either file. An edit to .git/ could add a hook, which runs any command. + outside = (" /", "=/", " ~", "=~", "../", " ..", "$", "O/", "X/") + denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git *{shape}*)" for shape in outside)] # Only the clone's own settings: the user's add every checkout under ~/code to the readable trees. return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] -- 2.52.0 From e077fffade69b26c7703b3368ecb5d741b45872d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:32:37 +0200 Subject: [PATCH 08/20] =?UTF-8?q?Answer=20principles=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20the=20path=20shapes=20close?= =?UTF-8?q?=20the=20implicit=20no-index=20diff=20and=20the=20pathspec=20fi?= =?UTF-8?q?le,=20and=20the=20clone's=20.claude=20cannot=20be=20edited=20by?= =?UTF-8?q?=20the=20run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 3110e03226d8d9371c51e52d37aa208a6fde95e9 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:32:37 +0200 Subject: [PATCH 09/20] =?UTF-8?q?Answer=20stability=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20pathspec=20file=20is?= =?UTF-8?q?=20denied=20with=20every=20other=20path=20an=20argument=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 4625b805ebbec4ccb55dcae12c726897297a7923 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:32:42 +0200 Subject: [PATCH 10/20] Record in bench.py why the clone's settings need no deny --- workflow-bench/bench.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index 4f656d33..ed5c7020 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -48,7 +48,8 @@ def permission_flags(clone, version_dir, report): # before reading either file. An edit to .git/ could add a hook, which runs any command. outside = (" /", "=/", " ~", "=~", "../", " ..", "$", "O/", "X/") denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git *{shape}*)" for shape in outside)] - # Only the clone's own settings: the user's add every checkout under ~/code to the readable trees. + # Only the clone's own settings: the user's add every checkout under ~/code to the readable trees. A run + # cannot widen the clone's settings either: Claude Code refuses its edit to them, as a probe showed. return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] -- 2.52.0 From cf4072f69f2ade5d14242ec69b772dcaad42c989 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:53:27 +0200 Subject: [PATCH 11/20] =?UTF-8?q?Answer=20security=20round=203:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20answer=20holds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CHANGELOG.md | 2 +- workflow-bench/bench.py | 18 ++++----- workflow-bench/review-git.py | 73 ++++++++++++++++++++++++++++++++++++ workflow-bench/run-prompt.md | 4 +- 5 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 workflow-bench/review-git.py diff --git a/.gitignore b/.gitignore index d3efa6f5..1393e8ea 100644 --- a/.gitignore +++ b/.gitignore @@ -88,4 +88,5 @@ !workflow-bench/bench.py !workflow-bench/compare-prompt.md !workflow-bench/compare.py +!workflow-bench/review-git.py !workflow-bench/run-prompt.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a8152ca7..efc03eed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/`) and its report, read its clone and the copy of `~/.claude` it benches, and run `git log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` (also as `-am` or `-a -m`). A git argument that names a path outside the clone is denied: an absolute path, one from `~`, one through `..` or one through a shell variable. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. +- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review-git.py`, and no bare `git`: the wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit` under the clone with a scrubbed config, refusing an argument that names a path outside the clone and any option that reads a file, writes a file or runs a program. So no git argument, option, hook, redirect or shell substitution reaches beyond the clone. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index ed5c7020..1a1aa6d4 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -23,6 +23,7 @@ import sys import time BENCH = pathlib.Path(__file__).resolve().parent +REVIEW_GIT = BENCH / "review-git.py" SOURCES = pathlib.Path(os.environ["BENCH_SOURCES"]) CASES = { "cjk": ("151bf38^", "6c49912"), @@ -37,19 +38,16 @@ def permission_flags(clone, version_dir, report): """The tools a review needs, each limited to what it may touch; the run denies every other call.""" # A permission rule writes an absolute path as "//"; a trailing "/**" matches everything under it. trees = (f"/{clone}/**", f"/{version_dir}/**") - commands = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am", "commit -a -m") + # git can reach outside the clone through an argument, an option or a hook, and a quote or redirect can + # smuggle one past a text pattern. So the run gets no bare git: review-git.py is its one shell command + # and confines git to the clone (see its docstring). The clone's own .git and .claude stay unwritable, + # lest an edit plant a hook or widen the run's tools; the user's settings would add ~/code to the trees. allowed = [ "Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})", - *(f"Bash(git {command} *)" for command in commands), + f"Bash(python3 {REVIEW_GIT} *)", *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] - # git reaches a path outside the clone only through an argument that names one: absolute, from ~, up - # through "..", through a variable, or glued to -O or -X. With -m, git refuses -F and ignores -t - # before reading either file. An edit to .git/ could add a hook, which runs any command. - outside = (" /", "=/", " ~", "=~", "../", " ..", "$", "O/", "X/") - denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git *{shape}*)" for shape in outside)] - # Only the clone's own settings: the user's add every checkout under ~/code to the readable trees. A run - # cannot widen the clone's settings either: Claude Code refuses its edit to them, as a probe showed. + denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"] return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] @@ -96,7 +94,7 @@ def run(name): base, head = fresh_clone(case, clone) version_dir = BENCH / "versions" / version prompt = (BENCH / "run-prompt.md").read_text().format( - version_dir=version_dir, base=base, head=head, case=case, report=report) + version_dir=version_dir, base=base, head=head, case=case, report=report, review_git=REVIEW_GIT) log = BENCH / "logs" / f"{name}.{attempt}.jsonl" log.parent.mkdir(exist_ok=True) with log.open("w") as out: diff --git a/workflow-bench/review-git.py b/workflow-bench/review-git.py new file mode 100644 index 00000000..21629b4d --- /dev/null +++ b/workflow-bench/review-git.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +"""Run one git command for a bench review, confined to the clone: review-git.py ... + +The bench's review runs no bare git. It calls this wrapper, its one allowed command (bench.py's +permission_flags). The wrapper is git with everything that could reach outside the clone removed: +it accepts only the review's subcommands, each with no option that reads a file, writes a file or +runs a program; it refuses an argument that names a path outside the clone; and it runs git under +the clone with a scrubbed config, so no global or system config, hook, pager or external diff fires. +Quoting, redirects and `$` are the shell's, never git's, so they cannot smuggle a path past this. +The wrapper lives outside the clone, so the clone is not on Python's import path. +""" +import os +import subprocess +import sys + +SUBCOMMANDS = {"log", "diff", "show", "status", "ls-files", "add", "commit"} +# Options that read a file, write a file or run a program; "--no-index" lets diff read any two paths. +DENY_EXACT = {"--no-index", "-t"} +DENY_PREFIX = ("--output", "-O", "--pathspec-from-file", "-F", "--file", "--template", + "--exclude-from", "-X", "--git-dir", "--work-tree", "--exec-path", "--ext-diff", "--textconv") + + +def reject(reason): + sys.exit(f"review-git.py: refused: {reason}") + + +def bad_option(token): + name = token.split("=", 1)[0] + return name in DENY_EXACT or any(name.startswith(prefix) for prefix in DENY_PREFIX) + + +def bad_path(clone, arg): + # A revision such as HEAD~1 or a..b is not a path; a path that escapes the clone is refused. + if arg.startswith("/") or arg.startswith("~"): + return True + if arg == ".." or any(part == ".." for part in arg.split("/")): + return True + target = os.path.realpath(os.path.join(clone, arg)) + return os.path.lexists(target) and target != clone and not target.startswith(clone + os.sep) + + +def main(argv): + if len(argv) < 1 or argv[0] not in SUBCOMMANDS: + reject(f"subcommand must be one of {' '.join(sorted(SUBCOMMANDS))}") + sub, args = argv[0], argv[1:] + clone = os.path.realpath(os.getcwd()) + operands_only = False # Everything after "--" is a path operand. + skip_message = False # commit's -m value is free text, never a path. + for token in args: + if skip_message: + skip_message = False + continue + if not operands_only and token == "--": + operands_only = True + elif not operands_only and token.startswith("-"): + if bad_option(token): + reject(f"option not allowed: {token}") + short_m = not token.startswith("--") and token.endswith("m") # -m, -am + if sub == "commit" and "=" not in token and (token == "--message" or short_m): + skip_message = True # the next token is the commit message, free text, never a path. + elif bad_path(clone, token): + reject(f"argument names a path outside the clone: {token}") + env = {**os.environ, "GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_SYSTEM": "/dev/null", + "GIT_CONFIG_NOSYSTEM": "1", "GIT_PAGER": "cat", "GIT_TERMINAL_PROMPT": "0"} + for name in ("GIT_EXTERNAL_DIFF", "GIT_SSH", "GIT_SSH_COMMAND", "GIT_PROXY_COMMAND", "GIT_CONFIG"): + env.pop(name, None) + git = ["git", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", + "-c", "core.pager=cat", "-c", "protocol.ext.allow=never", sub, *args] + return subprocess.run(git, cwd=clone, env=env).returncode + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/workflow-bench/run-prompt.md b/workflow-bench/run-prompt.md index 27ef4f27..b5713ddb 100644 --- a/workflow-bench/run-prompt.md +++ b/workflow-bench/run-prompt.md @@ -15,10 +15,10 @@ Report: write it to `{report}`. - Launch every agent in the foreground (`run_in_background: false`): background agents die when this headless turn ends. - No remote and no forge: skip the PR, CI, the external auto-reviewer and the merge; review locally. -- The shell runs only git, so run no code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities. +- Run every git command through `python3 {review_git} `, never bare `git`: that wrapper is the only shell command allowed, and it confines git to this clone. Run no other code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities. - Skip the comprehension check; say so in the report. - No human is reachable. Where the process names a no-human branch, take it; where it names none, take your recommendation and list the question in the report. -- Commit each round's fixes on `chunk`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. +- Commit each round's fixes on `chunk` with `python3 {review_git} commit`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. ## Report -- 2.52.0 From a9b617f9e598c1aedfcd40526e759bcc8f4c9221 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:53:27 +0200 Subject: [PATCH 12/20] =?UTF-8?q?Answer=20principles=20round=203:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20every=20git=20command=20goe?= =?UTF-8?q?s=20through=20review-git.py,=20which=20refuses=20the=20quoted?= =?UTF-8?q?=20paths,=20redirects=20and=20.git=20and=20.claude=20writes=20a?= =?UTF-8?q?=20pattern=20missed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 4438ab04f3d9e6c500465099b50e7cb0c6fc20f2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 20:53:27 +0200 Subject: [PATCH 13/20] =?UTF-8?q?Answer=20stability=20round=203:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20wrapper=20refuses=20-?= =?UTF-8?q?-output=20and=20every=20other=20option=20that=20writes=20or=20r?= =?UTF-8?q?uns,=20with=20bare=20git=20denied?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From b30c91aafcda786ad65b5831af996f87a6c3018a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:30:24 +0200 Subject: [PATCH 14/20] =?UTF-8?q?Answer=20stability=20round=204:=202=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20the=20wrapper=20allows=20on?= =?UTF-8?q?ly=20listed=20options,=20takes=20the=20clone=20from=20the=20env?= =?UTF-8?q?ironment,=20and=20skips=20only=20a=20message=20its=20flag=20tak?= =?UTF-8?q?es=20whole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- CHANGELOG.md | 2 +- README.md | 2 +- todo.md | 2 +- workflow-bench/bench.py | 15 ++-- workflow-bench/review-git.py | 73 ---------------- workflow-bench/review_git.py | 107 +++++++++++++++++++++++ workflow-bench/run-prompt.md | 4 +- workflow-bench/test_review_git.py | 135 ++++++++++++++++++++++++++++++ 9 files changed, 258 insertions(+), 85 deletions(-) delete mode 100644 workflow-bench/review-git.py create mode 100644 workflow-bench/review_git.py create mode 100644 workflow-bench/test_review_git.py diff --git a/.gitignore b/.gitignore index 1393e8ea..cbc50bba 100644 --- a/.gitignore +++ b/.gitignore @@ -88,5 +88,6 @@ !workflow-bench/bench.py !workflow-bench/compare-prompt.md !workflow-bench/compare.py -!workflow-bench/review-git.py +!workflow-bench/review_git.py !workflow-bench/run-prompt.md +!workflow-bench/test_review_git.py diff --git a/CHANGELOG.md b/CHANGELOG.md index efc03eed..7fba327b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `workflow-bench/bench.py` gives each run a fixed list of allowed tools, where it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review-git.py`, and no bare `git`: the wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit` under the clone with a scrubbed config, refusing an argument that names a path outside the clone and any option that reads a file, writes a file or runs a program. So no git argument, option, hook, redirect or shell substitution reaches beyond the clone. It loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs to run a project's code or tests to say in its report that it could not. +- `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/README.md b/README.md index f3460ce0..15da6745 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it. - `subagent-rung [--plan] ` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule. -Test on the host, with `uv` on `PATH` to fetch mypy and the Python version Install names (`docs/decisions.md` → `bin/`): `python3 -m unittest discover -s bin -p 'test_*.py'` +Test on the host, with `uv` on `PATH` to fetch mypy and the Python version Install names (`docs/decisions.md` → `bin/`): `python3 -m unittest discover -s bin -p 'test_*.py'`. Test the bench's git wrapper with `python3 -m unittest discover -s workflow-bench -p 'test_*.py'`. To mutation-test a changed module, copy `bin/` to a scratch directory (`cp -r bin "$scratch"`): mutmut writes files beside its config. In the copy, name the module and its tests in a `setup.cfg`, as below for `score_outcomes/outcomes.py`. Leave out each test class that starts a tool's launcher through `subprocess`: a mutated module fails to load in a process mutmut did not start. diff --git a/todo.md b/todo.md index d6c3c538..8b58dedf 100644 --- a/todo.md +++ b/todo.md @@ -332,7 +332,7 @@ The maintainability senior and the inherited architect of PR #257's scoring run "Most, if not all, code should have automated tests", in `principles/technical-principles.md`: `compare.blind()` keeps the comparison blind, and a version name it misses invalidates the bench silently. -The tests also cover `workflow-bench/bench.py`'s `permission_flags`, with a probe: a headless claude given its flags is denied a read of a file outside the granted trees, a `git -c alias.x=… x` and a `git diff --no-index`, and is allowed the review's own git commands. +The tests also cover `workflow-bench/bench.py`'s `permission_flags`, with a probe of a headless claude given its flags. It is denied a read outside the granted trees, a bare `git status`, and wrapper calls with `--output`, `--no-index`, a glued `-aF/abs`, `--fil=/abs` or a path outside the clone. A `cd && python3 …` acts on the clone only. It is allowed the wrapper's `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m`. `workflow-bench/test_review_git.py` tests the wrapper's refusals directly. ### 4. Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index 1a1aa6d4..3f53114d 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -23,7 +23,7 @@ import sys import time BENCH = pathlib.Path(__file__).resolve().parent -REVIEW_GIT = BENCH / "review-git.py" +REVIEW_GIT = BENCH / "review_git.py" SOURCES = pathlib.Path(os.environ["BENCH_SOURCES"]) CASES = { "cjk": ("151bf38^", "6c49912"), @@ -38,16 +38,19 @@ def permission_flags(clone, version_dir, report): """The tools a review needs, each limited to what it may touch; the run denies every other call.""" # A permission rule writes an absolute path as "//"; a trailing "/**" matches everything under it. trees = (f"/{clone}/**", f"/{version_dir}/**") - # git can reach outside the clone through an argument, an option or a hook, and a quote or redirect can - # smuggle one past a text pattern. So the run gets no bare git: review-git.py is its one shell command - # and confines git to the clone (see its docstring). The clone's own .git and .claude stay unwritable, - # lest an edit plant a hook or widen the run's tools; the user's settings would add ~/code to the trees. + # git can reach outside the clone through an argument, an option or a hook, so the run gets no bare git: + # review_git.py is its one shell command (see its docstring). The clone's own .git and .claude stay + # unwritable, lest an edit plant a hook or widen the run's tools. allowed = [ "Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})", + # Claude Code, not the wrapper, refuses what a shell adds to this command: a redirect, `$(…)`, backticks, + # or a second command after `;`, `&` or `&&`. It lets through `cd && …`, which is why run() names + # the clone in REVIEW_GIT_CLONE, and a pipe into a reader such as `| head`. f"Bash(python3 {REVIEW_GIT} *)", *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"] + # No "user" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks. return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] @@ -101,7 +104,7 @@ def run(name): subprocess.run( ["claude", "-p", prompt, *permission_flags(clone, version_dir, report), "--model", "claude-opus-5-5", "--output-format", "stream-json", "--verbose"], - cwd=clone, stdout=out, stderr=subprocess.STDOUT) + cwd=clone, env={**os.environ, "REVIEW_GIT_CLONE": str(clone)}, stdout=out, stderr=subprocess.STDOUT) if report.exists(): return f"{name}: done on attempt {attempt}" time.sleep(max(1200, rate_limit_reset(log) + 120 - time.time())) diff --git a/workflow-bench/review-git.py b/workflow-bench/review-git.py deleted file mode 100644 index 21629b4d..00000000 --- a/workflow-bench/review-git.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python3 -"""Run one git command for a bench review, confined to the clone: review-git.py ... - -The bench's review runs no bare git. It calls this wrapper, its one allowed command (bench.py's -permission_flags). The wrapper is git with everything that could reach outside the clone removed: -it accepts only the review's subcommands, each with no option that reads a file, writes a file or -runs a program; it refuses an argument that names a path outside the clone; and it runs git under -the clone with a scrubbed config, so no global or system config, hook, pager or external diff fires. -Quoting, redirects and `$` are the shell's, never git's, so they cannot smuggle a path past this. -The wrapper lives outside the clone, so the clone is not on Python's import path. -""" -import os -import subprocess -import sys - -SUBCOMMANDS = {"log", "diff", "show", "status", "ls-files", "add", "commit"} -# Options that read a file, write a file or run a program; "--no-index" lets diff read any two paths. -DENY_EXACT = {"--no-index", "-t"} -DENY_PREFIX = ("--output", "-O", "--pathspec-from-file", "-F", "--file", "--template", - "--exclude-from", "-X", "--git-dir", "--work-tree", "--exec-path", "--ext-diff", "--textconv") - - -def reject(reason): - sys.exit(f"review-git.py: refused: {reason}") - - -def bad_option(token): - name = token.split("=", 1)[0] - return name in DENY_EXACT or any(name.startswith(prefix) for prefix in DENY_PREFIX) - - -def bad_path(clone, arg): - # A revision such as HEAD~1 or a..b is not a path; a path that escapes the clone is refused. - if arg.startswith("/") or arg.startswith("~"): - return True - if arg == ".." or any(part == ".." for part in arg.split("/")): - return True - target = os.path.realpath(os.path.join(clone, arg)) - return os.path.lexists(target) and target != clone and not target.startswith(clone + os.sep) - - -def main(argv): - if len(argv) < 1 or argv[0] not in SUBCOMMANDS: - reject(f"subcommand must be one of {' '.join(sorted(SUBCOMMANDS))}") - sub, args = argv[0], argv[1:] - clone = os.path.realpath(os.getcwd()) - operands_only = False # Everything after "--" is a path operand. - skip_message = False # commit's -m value is free text, never a path. - for token in args: - if skip_message: - skip_message = False - continue - if not operands_only and token == "--": - operands_only = True - elif not operands_only and token.startswith("-"): - if bad_option(token): - reject(f"option not allowed: {token}") - short_m = not token.startswith("--") and token.endswith("m") # -m, -am - if sub == "commit" and "=" not in token and (token == "--message" or short_m): - skip_message = True # the next token is the commit message, free text, never a path. - elif bad_path(clone, token): - reject(f"argument names a path outside the clone: {token}") - env = {**os.environ, "GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_SYSTEM": "/dev/null", - "GIT_CONFIG_NOSYSTEM": "1", "GIT_PAGER": "cat", "GIT_TERMINAL_PROMPT": "0"} - for name in ("GIT_EXTERNAL_DIFF", "GIT_SSH", "GIT_SSH_COMMAND", "GIT_PROXY_COMMAND", "GIT_CONFIG"): - env.pop(name, None) - git = ["git", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", - "-c", "core.pager=cat", "-c", "protocol.ext.allow=never", sub, *args] - return subprocess.run(git, cwd=clone, env=env).returncode - - -if __name__ == "__main__": - sys.exit(main(sys.argv[1:])) diff --git a/workflow-bench/review_git.py b/workflow-bench/review_git.py new file mode 100644 index 00000000..35f46508 --- /dev/null +++ b/workflow-bench/review_git.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +"""Run one git command for a bench review, confined to the clone: review_git.py ... + +The bench's review runs no bare git: this wrapper is its one allowed shell command (bench.py's +permission_flags). bench.py names the clone in REVIEW_GIT_CLONE, and git runs there whatever the +working directory, with GIT_DIR and GIT_WORK_TREE pinned to it. + +The wrapper refuses every subcommand and option ALLOWED does not list, so a cluster of short options +or a long option cut to a prefix is refused too. An option that takes a value takes it glued, as +`--format=%h`. A commit needs `-m`, whose value is the one free-text argument. Every other argument +must name no path outside the clone. git runs with no global or system config, hook, pager or editor. +The wrapper checks the arguments git receives, after the shell has removed quotes and expanded `$`, +so no quoting hides a path from it. It lives outside the clone, so a module planted in the clone +cannot replace `os` or `subprocess`. +""" +from collections.abc import Callable +import os +import re +import subprocess +import sys + +OUTPUT = {"--name-only", "--name-status", "--no-color", "--stat", "--unified="} +# An entry ending in "=" allows that option with any glued value. +ALLOWED = { + "add": {"-A", "--all", "-u", "--update"}, + "commit": {"-a", "--all"}, + "diff": OUTPUT | {"--cached", "--check", "--staged", "--word-diff"}, + "log": OUTPUT | {"--author=", "--decorate", "--follow", "--format=", "--graph", "--grep=", "--max-count=", + "--oneline", "-p", "--patch", "--pretty=", "--reverse", "--since=", "--until="}, + "ls-files": {"--cached", "--deleted", "--exclude-standard", "--modified", "--others"}, + "show": OUTPUT | {"--format=", "--no-patch", "--oneline", "--pretty=", "-s"}, + "status": {"-b", "--branch", "--porcelain", "-s", "--short"}, +} +# The commit identity, since no config supplies one. +BENCH_IDENTITY = {"GIT_AUTHOR_NAME": "bench", "GIT_AUTHOR_EMAIL": "bench@localhost", + "GIT_COMMITTER_NAME": "bench", "GIT_COMMITTER_EMAIL": "bench@localhost"} +GIT = ["git", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-c", "core.pager=cat"] + + +def allowed_option(sub: str, token: str) -> bool: + options = ALLOWED[sub] + glued = any(token.startswith(option) for option in options if option.endswith("=")) + return token in options or glued or (sub == "log" and re.fullmatch(r"-[0-9]+", token) is not None) + + +def outside_clone(token: str, escapes: Callable[[str], bool]) -> bool: + # A revision range such as a..b is checked side by side, so `..` cannot climb out of the clone: + # ../x splits into "" and "/x". A leading ":" is pathspec magic, which can name the repository's top. + sides = re.split(r"\.\.\.?", token) + return token.startswith(":") or escapes(token) or any(side.startswith(("/", "~")) or escapes(side) for side in sides) + + +def refusal(argv: list[str], escapes: Callable[[str], bool]) -> str | None: + """Why the wrapper refuses `git `, or None; escapes(path) is whether path names an existing file outside the clone.""" + if not argv or argv[0] not in ALLOWED: + return f"subcommand must be one of {' '.join(sorted(ALLOWED))}" + sub = argv[0] + has_message = operands_only = message_next = False + for token in argv[1:]: + if message_next: + message_next = False + elif operands_only or not token.startswith("-"): + if outside_clone(token, escapes): + return f"argument names a path outside the clone: {token}" + elif token == "--": + operands_only = True + elif sub == "commit" and token in ("-m", "-am", "--message"): + has_message = message_next = True + elif sub == "commit" and token.startswith(("-m", "--message=")): + has_message = True + elif not allowed_option(sub, token): + return f"option not allowed: {token}; {sub} takes {' '.join(sorted(ALLOWED[sub]))}" + if sub == "commit" and not has_message: + return "commit needs -m " + return None + + +def git_env(environ: dict[str, str], clone: str) -> dict[str, str]: + """The inherited environment without any variable that names a program or a repository, with git pinned to the clone.""" + kept = {name: value for name, value in environ.items() + if not name.startswith("GIT_") and name not in ("EDITOR", "PAGER", "SSH_ASKPASS", "VISUAL")} + return {**kept, **BENCH_IDENTITY, "GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1", "GIT_DIR": os.path.join(clone, ".git"), + "GIT_EDITOR": "true", "GIT_PAGER": "cat", "GIT_TERMINAL_PROMPT": "0", "GIT_WORK_TREE": clone} + + +def escapes(clone: str, path: str) -> bool: + target = os.path.realpath(os.path.join(clone, path)) + return os.path.lexists(target) and os.path.commonpath([clone, target]) != clone + + +def refuse(reason: str) -> int: + print(f"review_git.py: refused: {reason}", file=sys.stderr) + return 2 + + +def main(argv: list[str], environ: dict[str, str]) -> int: + if not environ.get("REVIEW_GIT_CLONE"): + return refuse("REVIEW_GIT_CLONE must name the clone") + clone = os.path.realpath(environ["REVIEW_GIT_CLONE"]) + reason = refusal(argv, lambda path: escapes(clone, path)) + if reason is not None: + return refuse(reason) + return subprocess.run([*GIT, *argv], cwd=clone, env=git_env(environ, clone)).returncode + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:], dict(os.environ))) diff --git a/workflow-bench/run-prompt.md b/workflow-bench/run-prompt.md index b5713ddb..a482232f 100644 --- a/workflow-bench/run-prompt.md +++ b/workflow-bench/run-prompt.md @@ -15,10 +15,10 @@ Report: write it to `{report}`. - Launch every agent in the foreground (`run_in_background: false`): background agents die when this headless turn ends. - No remote and no forge: skip the PR, CI, the external auto-reviewer and the merge; review locally. -- Run every git command through `python3 {review_git} `, never bare `git`: that wrapper is the only shell command allowed, and it confines git to this clone. Run no other code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities. +- Run every git command through `python3 {review_git} `, never bare `git`: that wrapper is the only shell command allowed. It runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit`. Where the process asks for another git command, do without it and list it under Ambiguities. Run no other code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities. - Skip the comprehension check; say so in the report. - No human is reachable. Where the process names a no-human branch, take it; where it names none, take your recommendation and list the question in the report. -- Commit each round's fixes on `chunk` with `python3 {review_git} commit`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. +- Commit each round's fixes on `chunk` with `python3 {review_git} commit -m `, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report. ## Report diff --git a/workflow-bench/test_review_git.py b/workflow-bench/test_review_git.py new file mode 100644 index 00000000..f3a48959 --- /dev/null +++ b/workflow-bench/test_review_git.py @@ -0,0 +1,135 @@ +import os +import pathlib +import subprocess +import sys +import tempfile +import unittest + +from review_git import git_env, refusal + +WRAPPER = pathlib.Path(__file__).resolve().parent / "review_git.py" +# Paths the fake filesystem resolves to an existing file outside the clone. +OUTSIDE = {"..", "link-out"} + + +def escapes(path: str) -> bool: + return path in OUTSIDE + + +class Refusal(unittest.TestCase): + def test_refuses_an_option_outside_the_subcommands_allowlist(self): + for argv in ( + ["commit", "-aF/abs/secret"], ["commit", "-t/abs/template", "-m", "x"], ["diff", "-RO/abs/out"], + ["commit", "--fil=/abs/secret"], ["commit", "--templ=/abs/template", "-m", "x"], + ["add", "--pathspec-from=/abs/list"], ["add", "--pathspec-f=list"], ["ls-files", "--exclude-f=/abs/x"], + ["diff", "--ext"], ["ls-files", "-oX/abs/x"], ["diff", "--output=.git/config"], ["diff", "--no-index", "a", "b"], + ["commit", "-S", "-m", "x"], ["commit", "--gpg-sign", "-m", "x"], ["commit", "-e", "-m", "x"], + ["commit", "--edit", "-m", "x"], ["commit", "-c", "HEAD"], ["add", "-e"], ["add", "-p"], ["add", "-i"], + ["add", "--patch"], ["log", "--help"], + ): + with self.subTest(argv): + self.assertIn(argv[1], refusal(argv, escapes) or "") + + def test_reads_an_option_after_a_message_glued_to_m(self): + for argv in (["commit", "-mm", "--pathspec-from-file=/secret"], ["commit", "-mfixm", "--pathspec-from-file=/secret"]): + with self.subTest(argv): + self.assertIn("--pathspec-from-file=/secret", refusal(argv, escapes) or "") + + def test_refuses_a_commit_without_a_message(self): + for argv in (["commit"], ["commit", "-a"]): + with self.subTest(argv): + self.assertIsNotNone(refusal(argv, escapes)) + + def test_refuses_a_subcommand_outside_the_review(self): + for argv in ([], ["config", "core.pager", "sh"], ["-c", "alias.x=!sh", "x"], ["push"]): + with self.subTest(argv): + self.assertIsNotNone(refusal(argv, escapes)) + + def test_refuses_an_argument_naming_a_path_outside_the_clone(self): + for argv in ( + ["add", "/etc/passwd"], ["diff", "~/.ssh/id_rsa"], ["diff", "--", "../other/f"], ["add", ".."], + ["show", "link-out"], ["diff", "HEAD..link-out"], ["diff", "a/../../b"], ["diff", "HEAD..~/x"], + ["log", ":(top)"], ["log", ":/"], ["add", "--", "/etc/passwd"], ["commit", "-m", "x", "/etc/passwd"], + ): + with self.subTest(argv): + self.assertIn(argv[-1], refusal(argv, escapes) or "") + + def test_allows_the_reviews_own_commands(self): + for argv in ( + ["log", "--oneline", "abc123..chunk"], ["log", "-5"], ["log", "--max-count=3", "--format=%h %s"], + ["log", "--stat", "HEAD~1..HEAD"], ["log", "--pretty=%H", "--", "src/a.py"], ["diff", "base...chunk", "--stat"], + ["diff", "--cached"], ["diff", "--name-only", "HEAD~1"], ["diff", "--", "src"], ["show", "HEAD"], + ["show", "--stat", "abc123"], ["show", "HEAD:README.md"], ["status"], ["status", "--short"], ["ls-files"], + ["ls-files", "--others", "--exclude-standard"], ["add", "-A"], ["add", "--", "src/a.py"], + ["commit", "-m", "case - review: fix"], ["commit", "-am", "fix"], ["commit", "-a", "-m", "fix"], + ["commit", "-m", "/a message, never a path"], ["commit", "-mfix"], ["commit", "--message=fix"], + ["commit", "--message", "fix"], + ): + with self.subTest(argv): + self.assertIsNone(refusal(argv, escapes)) + + +class GitEnv(unittest.TestCase): + def test_pins_git_to_the_clone_and_drops_every_program_the_environment_names(self): + inherited = {"PATH": "/bin", "GIT_DIR": "/other/.git", "GIT_EDITOR": "sh", "GIT_SEQUENCE_EDITOR": "sh", + "EDITOR": "sh", "VISUAL": "sh", "PAGER": "sh", "GIT_ASKPASS": "sh", "SSH_ASKPASS": "sh", "GIT_EXTERNAL_DIFF": "sh"} + env = git_env(inherited, "/clone") + self.assertEqual({name: env.get(name) for name in (*inherited, "GIT_WORK_TREE")}, { + "PATH": "/bin", "GIT_DIR": "/clone/.git", "GIT_EDITOR": "true", "GIT_SEQUENCE_EDITOR": None, "EDITOR": None, + "VISUAL": None, "PAGER": None, "GIT_ASKPASS": None, "SSH_ASKPASS": None, "GIT_EXTERNAL_DIFF": None, + "GIT_WORK_TREE": "/clone"}) + + def test_names_the_committer_whatever_the_inherited_environment_holds(self): + env = git_env({"GIT_AUTHOR_NAME": "someone", "EMAIL": "x@y"}, "/clone") + self.assertEqual([env[name] for name in ("GIT_AUTHOR_NAME", "GIT_COMMITTER_NAME")], ["bench", "bench"]) + + +class Wrapper(unittest.TestCase): + def setUp(self): + scratch = tempfile.TemporaryDirectory() + self.addCleanup(scratch.cleanup) + self.root = pathlib.Path(scratch.name) + self.clone = self.root / "clone" + self.other = self.root / "other" + self.env = {name: value for name, value in os.environ.items() if not name.startswith(("GIT_", "REVIEW_GIT_"))} + self.env.update(EMAIL="bench@example.com", GIT_CONFIG_GLOBAL="/dev/null", GIT_CONFIG_NOSYSTEM="1") + for repo in (self.clone, self.other): + subprocess.run(["git", "init", "-q", "-b", "chunk", str(repo)], check=True, env=self.env) + (repo / "a.txt").write_text("one\n") + subprocess.run(["git", "-C", str(repo), "add", "a.txt"], check=True, env=self.env) + subprocess.run(["git", "-C", str(repo), "commit", "-qm", "start"], check=True, env=self.env) + + def wrapper(self, *args, cwd, clone_env=True): + env = {**self.env, "REVIEW_GIT_CLONE": str(self.clone)} if clone_env else self.env + return subprocess.run([sys.executable, str(WRAPPER), *args], cwd=cwd, env=env, capture_output=True, text=True) + + def subjects(self, repo): + return subprocess.run(["git", "-C", str(repo), "log", "--format=%s"], check=True, env=self.env, + capture_output=True, text=True).stdout.split("\n")[:-1] + + def test_an_edit_is_added_and_committed_on_the_clone_whatever_the_working_directory(self): + (self.clone / "a.txt").write_text("two\n") + (self.other / "a.txt").write_text("two\n") + self.wrapper("add", "-A", cwd=self.other) + self.wrapper("commit", "-m", "case - review: fix", cwd=self.other) + self.assertEqual((self.subjects(self.clone), self.subjects(self.other)), (["case - review: fix", "start"], ["start"])) + + def test_a_refused_output_option_leaves_git_config_unchanged(self): + config = (self.clone / ".git" / "config").read_bytes() + ran = self.wrapper("diff", "--output=.git/config", cwd=self.clone) + self.assertEqual((ran.returncode != 0, (self.clone / ".git" / "config").read_bytes()), (True, config)) + + def test_refuses_to_run_without_the_clone_named(self): + (self.clone / "a.txt").write_text("two\n") + ran = self.wrapper("diff", cwd=self.clone, clone_env=False) + self.assertEqual((ran.returncode != 0, ran.stdout), (True, "")) + + def test_refuses_a_link_in_the_clone_to_a_file_outside_it(self): + (self.root / "secret").write_text("token\n") + (self.clone / "link-out").symlink_to(self.root / "secret") + ran = self.wrapper("diff", "--no-color", "link-out", cwd=self.clone) + self.assertEqual((ran.returncode != 0, "token" in ran.stdout), (True, False)) + + +if __name__ == "__main__": + unittest.main() -- 2.52.0 From 988f608bded6c10b173259ed68e821e1de84ea95 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:30:24 +0200 Subject: [PATCH 15/20] =?UTF-8?q?Answer=20principles=20round=204:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20the=20refusal=20is=20a=20pu?= =?UTF-8?q?re=20function=20over=20an=20allowlist,=20with=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From e57309a4153cc8add3336f1f2368852f72f9d92f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:30:24 +0200 Subject: [PATCH 16/20] =?UTF-8?q?Answer=20prose=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1;=20the=20claims=20name=20only?= =?UTF-8?q?=20what=20the=20wrapper=20does,=20and=20the=20wrapper,=20bench?= =?UTF-8?q?=20rule=20and=20item=2068=20are=20reworded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 57cd5f76a436c1635bea73d4052438a5a8288ac5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:42:11 +0200 Subject: [PATCH 17/20] =?UTF-8?q?Answer=20security=20round=204:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20refuse=20the=20format=20opt?= =?UTF-8?q?ions=20that=20start=20gpg,=20and=20load=20no=20settings=20from?= =?UTF-8?q?=20the=20case's=20clone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- workflow-bench/bench.py | 5 +++-- workflow-bench/review_git.py | 8 ++++---- workflow-bench/test_review_git.py | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fba327b..e560a603 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no user settings, so `~/.claude/settings.json`'s hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. +- `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no settings or MCP servers from `~/.claude` or from the case's clone, so their hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. - `todo.md` ranks items by value per cost: this setup's own plan uses `Score = 100 * V / (2**S + 8)`, where 8 is a chunk's fixed cost, about one size-3 change, and `rank_todo.py --help` shows it. A Moves column replaces A, G and Goals, naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`. V sums each named goal's weight times its move. `rank_todo.py` weighs each achieve goal by its position in README.md, the first heaviest, so the goal weights table goes. An item names the most specific goal it moves, never a goal beside its own sub-goal. `rules/todo-items.md` and `rank_todo.py --help` show the new shape. diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index 3f53114d..5b840436 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -50,8 +50,9 @@ def permission_flags(clone, version_dir, report): *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"] - # No "user" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks. - return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none", + # No "user" or "project" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks, + # and a case's committed .claude/settings.json could run its own; --strict-mcp-config ignores a committed .mcp.json. + return ["--setting-sources", "local", "--strict-mcp-config", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] diff --git a/workflow-bench/review_git.py b/workflow-bench/review_git.py index 35f46508..45e87ac6 100644 --- a/workflow-bench/review_git.py +++ b/workflow-bench/review_git.py @@ -7,7 +7,7 @@ working directory, with GIT_DIR and GIT_WORK_TREE pinned to it. The wrapper refuses every subcommand and option ALLOWED does not list, so a cluster of short options or a long option cut to a prefix is refused too. An option that takes a value takes it glued, as -`--format=%h`. A commit needs `-m`, whose value is the one free-text argument. Every other argument +`--grep=fix`. A commit needs `-m`, whose value is the one free-text argument. Every other argument must name no path outside the clone. git runs with no global or system config, hook, pager or editor. The wrapper checks the arguments git receives, after the shell has removed quotes and expanded `$`, so no quoting hides a path from it. It lives outside the clone, so a module planted in the clone @@ -25,10 +25,10 @@ ALLOWED = { "add": {"-A", "--all", "-u", "--update"}, "commit": {"-a", "--all"}, "diff": OUTPUT | {"--cached", "--check", "--staged", "--word-diff"}, - "log": OUTPUT | {"--author=", "--decorate", "--follow", "--format=", "--graph", "--grep=", "--max-count=", - "--oneline", "-p", "--patch", "--pretty=", "--reverse", "--since=", "--until="}, + "log": OUTPUT | {"--author=", "--decorate", "--follow", "--graph", "--grep=", "--max-count=", + "--oneline", "-p", "--patch", "--reverse", "--since=", "--until="}, "ls-files": {"--cached", "--deleted", "--exclude-standard", "--modified", "--others"}, - "show": OUTPUT | {"--format=", "--no-patch", "--oneline", "--pretty=", "-s"}, + "show": OUTPUT | {"--no-patch", "--oneline", "-s"}, "status": {"-b", "--branch", "--porcelain", "-s", "--short"}, } # The commit identity, since no config supplies one. diff --git a/workflow-bench/test_review_git.py b/workflow-bench/test_review_git.py index f3a48959..16216851 100644 --- a/workflow-bench/test_review_git.py +++ b/workflow-bench/test_review_git.py @@ -25,7 +25,7 @@ class Refusal(unittest.TestCase): ["diff", "--ext"], ["ls-files", "-oX/abs/x"], ["diff", "--output=.git/config"], ["diff", "--no-index", "a", "b"], ["commit", "-S", "-m", "x"], ["commit", "--gpg-sign", "-m", "x"], ["commit", "-e", "-m", "x"], ["commit", "--edit", "-m", "x"], ["commit", "-c", "HEAD"], ["add", "-e"], ["add", "-p"], ["add", "-i"], - ["add", "--patch"], ["log", "--help"], + ["add", "--patch"], ["log", "--help"], ["log", "--format=%h %G?"], ["show", "--pretty=%GS"], ): with self.subTest(argv): self.assertIn(argv[1], refusal(argv, escapes) or "") @@ -56,8 +56,8 @@ class Refusal(unittest.TestCase): def test_allows_the_reviews_own_commands(self): for argv in ( - ["log", "--oneline", "abc123..chunk"], ["log", "-5"], ["log", "--max-count=3", "--format=%h %s"], - ["log", "--stat", "HEAD~1..HEAD"], ["log", "--pretty=%H", "--", "src/a.py"], ["diff", "base...chunk", "--stat"], + ["log", "--oneline", "abc123..chunk"], ["log", "-5"], ["log", "--max-count=3", "--oneline"], + ["log", "--stat", "HEAD~1..HEAD"], ["log", "--oneline", "--", "src/a.py"], ["diff", "base...chunk", "--stat"], ["diff", "--cached"], ["diff", "--name-only", "HEAD~1"], ["diff", "--", "src"], ["show", "HEAD"], ["show", "--stat", "abc123"], ["show", "HEAD:README.md"], ["status"], ["status", "--short"], ["ls-files"], ["ls-files", "--others", "--exclude-standard"], ["add", "-A"], ["add", "--", "src/a.py"], -- 2.52.0 From 53e87d1051211a38e5323c1c18da4bfa5ca9ec2c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:54:18 +0200 Subject: [PATCH 18/20] =?UTF-8?q?Answer=20security=20round=205:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20load=20no=20settings=20sour?= =?UTF-8?q?ce=20at=20all,=20and=20answer=20stability=20round=205's=20nit?= =?UTF-8?q?=20with=20a=20test=20that=20no=20config=20or=20hook=20program?= =?UTF-8?q?=20runs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workflow-bench/bench.py | 7 ++++--- workflow-bench/test_review_git.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/workflow-bench/bench.py b/workflow-bench/bench.py index 5b840436..c8486335 100755 --- a/workflow-bench/bench.py +++ b/workflow-bench/bench.py @@ -50,9 +50,10 @@ def permission_flags(clone, version_dir, report): *(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees), ] denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"] - # No "user" or "project" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks, - # and a case's committed .claude/settings.json could run its own; --strict-mcp-config ignores a committed .mcp.json. - return ["--setting-sources", "local", "--strict-mcp-config", "--permission-mode", "dontAsk", "--permission-prompts", "none", + # No settings source: ~/.claude/settings.json would add ~/code to the trees and run its hooks, and a case's + # committed .claude/settings.json or settings.local.json could run its own. --strict-mcp-config ignores a + # committed .mcp.json. + return ["--setting-sources", "", "--strict-mcp-config", "--permission-mode", "dontAsk", "--permission-prompts", "none", "--allowedTools", *allowed, "--disallowedTools", *denied] diff --git a/workflow-bench/test_review_git.py b/workflow-bench/test_review_git.py index 16216851..05950147 100644 --- a/workflow-bench/test_review_git.py +++ b/workflow-bench/test_review_git.py @@ -119,6 +119,25 @@ class Wrapper(unittest.TestCase): ran = self.wrapper("diff", "--output=.git/config", cwd=self.clone) self.assertEqual((ran.returncode != 0, (self.clone / ".git" / "config").read_bytes()), (True, config)) + def test_runs_no_program_that_a_config_or_hook_names(self): + marker = self.root / "ran" + program = self.root / "program.sh" + program.write_text(f"#!/bin/sh\ntouch {marker}\n") + program.chmod(0o755) + home = self.root / "home" + home.mkdir() + (home / ".gitconfig").write_text(f"[diff]\n\texternal = {program}\n") + (self.clone / ".git" / "hooks" / "pre-commit").write_text(f"#!/bin/sh\ntouch {marker}\n") + (self.clone / ".git" / "hooks" / "pre-commit").chmod(0o755) + with (self.clone / ".git" / "config").open("a") as config: + config.write(f"[core]\n\tfsmonitor = {program}\n") + (self.clone / "a.txt").write_text("two\n") + self.env["HOME"] = str(home) + self.wrapper("diff", cwd=self.clone) + self.wrapper("status", cwd=self.clone) + self.wrapper("commit", "-a", "-m", "x", cwd=self.clone) + self.assertFalse(marker.exists()) + def test_refuses_to_run_without_the_clone_named(self): (self.clone / "a.txt").write_text("two\n") ran = self.wrapper("diff", cwd=self.clone, clone_env=False) -- 2.52.0 From df624524b78325076a4844a6413c0a790743b842 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 22:54:18 +0200 Subject: [PATCH 19/20] =?UTF-8?q?Answer=20stability=20round=205:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20allowlist=20held=20un?= =?UTF-8?q?der=2022=20mutants,=20and=20the=20config-protection=20test=20is?= =?UTF-8?q?=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From c3885c0d1b60137334a8825333f222b3661ef6f1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:04:18 +0200 Subject: [PATCH 20/20] =?UTF-8?q?Answer=20security=20round=206:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20the=20answer=20holds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0