From 81260cdaf0653d51a2c144b0ef65beb76bcafba0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 02:03:34 +0100 Subject: [PATCH 1/8] Record the reading cost of the last finished chunk --- docs/reading-cost.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 551060b2..f21b5ba1 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -1378,3 +1378,15 @@ Read most (opens and searches): - `bin/release_plan/test_ranking.py` 3 - `CLAUDE.md` 2 - `rules/todo-items.md` 2 + +## Reading cost, chunk ee606830671d, finished 2026-11-09T00:59:33Z + +71673 new input tokens before the first commit. + +Read most (opens and searches): + +- `todo.md` 8 +- `bin/score_outcomes/results.py` 3 +- `bin/score_outcomes/test_score_outcomes.py` 3 +- `bin/score_outcomes/main.py` 2 +- `README.md` 1 -- 2.52.0 From 4d25e43c5ebd932c710d2274d069d788b294436a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 02:03:34 +0100 Subject: [PATCH 2/8] Open, mark ready and merge a chunk's pull request with chunk-pr, which picks tea or gh from the remote --- .gitignore | 3 + CHANGELOG.md | 1 + CLAUDE.md | 1 + README.md | 2 + bin/chunk-pr | 9 +++ bin/chunk_pr/__init__.py | 0 bin/chunk_pr/main.py | 129 ++++++++++++++++++++++++++++++++++ bin/chunk_pr/test_chunk_pr.py | 125 ++++++++++++++++++++++++++++++++ bin/deploy_release/forge.py | 2 +- skills/larv-review/SKILL.md | 8 +-- todo.md | 5 -- 11 files changed, 275 insertions(+), 10 deletions(-) create mode 100755 bin/chunk-pr create mode 100644 bin/chunk_pr/__init__.py create mode 100644 bin/chunk_pr/main.py create mode 100644 bin/chunk_pr/test_chunk_pr.py diff --git a/.gitignore b/.gitignore index 10bd194b..a368caed 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ !bin/ !bin/branch_chunks/ !bin/branch_chunks/*.py +!bin/chunk-pr +!bin/chunk_pr/ +!bin/chunk_pr/*.py !bin/chunk-preflight !bin/chunk_preflight/ !bin/chunk_preflight/*.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 794b6cc0..c06717f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `chunk-pr open|ready|merge` opens a chunk's pull request as a draft, marks it ready and merges it, with `gh` or `tea` as the remote needs, and merges only when told the gate passed. `larv-review` and `CLAUDE.md` now use it. - `score-outcomes` now gives, where most of the chunks it counts for L hold no ๐Ÿ”ด, the share of chunks with a ๐Ÿ”ด at each L in place of L's rank correlation by ๐Ÿ”ด findings. - `todo-item add` now files an item in `todo.md` with one command. It takes `Next ID` as the item's ID, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file. - `todo-item finish ` now removes a finished item's row and detail from `todo.md`. With `--changelog `, it also adds that bullet first under `CHANGELOG.md` โ†’ `## Unreleased`. Where a `CHANGELOG.md` exists, it refuses to run without `--changelog ` or `--no-changelog`, so no bullet is left out by mistake. diff --git a/CLAUDE.md b/CLAUDE.md index 90db7dbd..db3b0ea9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -95,6 +95,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - Branch for a ticket: exactly the ticket ID, nothing more. `ABC-123`, never `ABC-123-some-description`. - Branch for a `todo.md` item without a ticket: `item-`, in the worktree `-item-` beside the checkout, as `chunk-preflight` makes them. - Use `gh` on GitHub remotes and `tea` on Gitea remotes (e.g. `gitea.larvit.se`) โ€” same command shape: `tea pr list|create`, `tea issue`, `tea release`, `tea api`. Everything in this section applies to both. +- Open a chunk's pull request as a draft, mark it ready and merge it with `~/.claude/bin/chunk-pr`, which picks `gh` or `tea` from the remote; `chunk-pr --help` says how. ## Handoffs - Write no handoff document. The repo holds everything the next session needs: the plan, the decisions, and every script, sketch or measurement those depend on. A file outside the repo is unreachable from another machine's checkout. diff --git a/README.md b/README.md index 7a7e11b2..c6ba7fba 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that thro Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by their path, such as `~/.claude/bin/metric-bench`, from the project's checkout. Those under `~/.claude` are the release's; test a change to one from `~/code/claude-config/bin`. - `chunk-preflight` finds the mechanical facts a chunk starts from, and with `--worktree` makes its worktree; `loop-claude` runs it with `--worktree` before it routes each chunk, and `chunk-preflight --help` lists the facts. +- `chunk-pr open|ready|merge` opens a chunk's pull request as a draft, marks it ready and merges it, with `gh` on a GitHub origin and `tea` elsewhere; `chunk-pr --help` states the steps. - `deploy-release [--cut] []` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says. - `judge-replay ` replays loop-claude's judge on archived verdicts of the projects run on the model, and prints the lowest rung that, like each rung above it, returns them; `judge-replay --help` states the replay. - `larv-review ` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count, the scoring run's trigger, and the comprehension history's format and latest places, and its count of how often seats agree; `larv-review --help` states them. @@ -129,6 +130,7 @@ Then, in the copy: `uvx --with pytest==9.2.0 'mutmut>=3,<4' run && uvx --with py `bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests. Beside the packages, `bin/`'s root holds only the launchers, the tools of one file with their tests, `test_env.py` and `failure.py`. `failure.py`'s `Failure`, which modules across `bin/` return for a failed step, belongs to no single package. `branch_chunks/`, `claude_code/`, `command_lines/`, `git_cli/`, `machine_load/`, `model_routing/`, `records/`, `release_plan/`, `review_rules/`, `rung_replay/` and `transcript_archive/` serve more than one tool. - `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path. +- `chunk_pr` imports `deploy_release`'s forge calls and `chunk_preflight`'s `forge_of`. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. - `deploy_release` imports `chunk_preflight`'s `forge_of`, which tells a GitHub origin from a Gitea one, and `release_plan`'s `release_standing`. - `git_cli/` runs git for every tool (`git_repo.py`), and reads the git calls in a shell command (`git_command.py`). diff --git a/bin/chunk-pr b/bin/chunk-pr new file mode 100755 index 00000000..c863c5f3 --- /dev/null +++ b/bin/chunk-pr @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +import pathlib +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) + +from chunk_pr import main + +sys.exit(main.main(sys.argv[1:])) diff --git a/bin/chunk_pr/__init__.py b/bin/chunk_pr/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py new file mode 100644 index 00000000..9264586d --- /dev/null +++ b/bin/chunk_pr/main.py @@ -0,0 +1,129 @@ +"""Open the chunk's pull request as a draft, mark it ready, or merge it, with gh where origin is on GitHub and tea elsewhere. + +usage: chunk-pr open [<body>] + chunk-pr ready + chunk-pr merge --gate-passed + +Run it in the chunk's worktree, on the chunk's branch. Each step acts on the open pull request from +origin's own branch of that name whose head is the commit checked out, so push before ready and merge. + +open pushes the branch, setting its upstream, then opens a draft pull request into origin's + default branch, titled <title>: one line, as ~/.claude/CLAUDE.md โ†’ "Git, commits, and PRs" + says. Where that pull request is open already, it opens no other. +ready marks the pull request ready for review. Gitea has no draft state, so there it drops the + title's `WIP: ` prefix, which Gitea reads as a draft. +merge merges the pull request with a merge commit, and only while its head is still the commit + checked out, so a push after the gate is never merged. --gate-passed says the merge gate + passed on that commit; without it, chunk-pr refuses. A repo whose AGENTS.md names another + merge method merges through its forge instead. + +It prints the pull request's number, exit 0. A failure prints git's or the forge's reason, exit 1. +""" +import os +import sys + +from chunk_preflight.choices import forge_of +from chunk_preflight.gathered import Forge +from deploy_release.forge import gitea, open_pull, Run, runner +from failure import Failure + +USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr ready | chunk-pr merge --gate-passed" + + +def main(argv: list[str]) -> int: + if argv[:1] in (["-h"], ["--help"]): + print(__doc__.strip()) + return 0 + done = step(argv, runner(os.getcwd())) + if isinstance(done, Failure): + print(f"chunk-pr: {done.reason}", file=sys.stderr) + return 1 + print(done) + return 0 + + +def step(argv: list[str], run: Run) -> str | Failure: + """Run the step argv names: the line to print, or a Failure. A malformed argv runs nothing.""" + match argv: + case ["open", title, *body] if len(body) <= 1: + if not title.strip() or "\n" in title: + return Failure("the title is one line of text") + return opened(title, body[0] if body else "", run) + case ["ready"]: + return marked_ready(run) + case ["merge", "--gate-passed"]: + return merged(run) + case ["merge"]: + return Failure("merge only once the gate has passed, and say so with --gate-passed") + return Failure(USAGE) + + +def checkout(run: Run) -> tuple[Forge, str, str] | Failure: + """The forge, the branch checked out and its head commit.""" + answers = [run(["git", *args]) for args in (["remote", "get-url", "origin"], ["symbolic-ref", "--short", "HEAD"], ["rev-parse", "HEAD"])] + failed = next((answer for answer in answers if isinstance(answer, Failure)), None) + if failed is not None: + return failed + origin, branch, head = (str(answer).strip() for answer in answers) + return forge_of(origin), branch, head + + +def pull(run: Run) -> tuple[Forge, str, str] | Failure: + """The forge, the number of the branch's open pull request at its head, and that head.""" + found = checkout(run) + if isinstance(found, Failure): + return found + forge, branch, head = found + number = open_pull(forge, branch, head, run) + if number is None: + return Failure(f"no pull request from origin's {branch} is open at {head[:12]}; push the branch, or open one with chunk-pr open") + return number if isinstance(number, Failure) else (forge, number, head) + + +def opened(title: str, body: str, run: Run) -> str | Failure: + found = checkout(run) + if isinstance(found, Failure): + return found + forge, branch, head = found + default = run(["git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]) + if isinstance(default, Failure): + return Failure(f"origin records no default branch; set it with `git remote set-head origin --auto`: {default.reason}") + base = default.strip().removeprefix("origin/") + pushed = run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) + if isinstance(pushed, Failure): + return pushed + number = open_pull(forge, branch, head, run) + if isinstance(number, str): + return f"Pull request #{number} is open already." + if isinstance(number, Failure): + return number + command = ["gh", "pr", "create"] if forge == "gh" else ["tea", "pulls", "create"] + created = run([*command, "--draft", "--head", branch, "--base", base, "--title", title, "--body" if forge == "gh" else "--description", body]) + if isinstance(created, Failure): + return created + number = open_pull(forge, branch, head, run) + if number is None: + return Failure(f"{command[0]} created the pull request, but no pull request from origin's {branch} is listed open at {head[:12]}") + return number if isinstance(number, Failure) else f"Opened draft pull request #{number}." + + +def marked_ready(run: Run) -> str | Failure: + found = pull(run) + if isinstance(found, Failure): + return found + forge, number, _ = found + ready = run(["gh", "pr", "ready", number] if forge == "gh" else ["tea", "pulls", "edit", number, "--ready"]) + return ready if isinstance(ready, Failure) else f"Marked pull request #{number} ready." + + +def merged(run: Run) -> str | Failure: + found = pull(run) + if isinstance(found, Failure): + return found + forge, number, head = found + # The forge refuses where the pull request's head has moved off head. + if forge == "gh": + done = run(["gh", "pr", "merge", number, "--merge", "--match-head-commit", head]) + else: + done = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", "Do=merge", f"head_commit_id={head}") + return done if isinstance(done, Failure) else f"Merged pull request #{number}." diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py new file mode 100644 index 00000000..e735bbcd --- /dev/null +++ b/bin/chunk_pr/test_chunk_pr.py @@ -0,0 +1,125 @@ +import json +import pathlib +import subprocess +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from chunk_pr.main import step +from failure import Failure +from test_env import isolated_env + +TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr" +GITHUB = "git@github.com:me/project.git" +GITEA = "ssh://git@gitea.example.org:22/me/project.git" +HEAD = "c0ffee" +GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"] +TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"] + + +class Forge: + """A checkout on branch item-7 at HEAD, whose origin is origin and whose default branch is main. Pull request #12 from item-7 is open at HEAD where open says so, and once a create has run. It records every command run.""" + + def __init__(self, origin: str, open: bool): + self.open = open + self.ran: list[list[str]] = [] + self.answers: dict[tuple[str, ...], str | Failure] = { + ("git", "remote", "get-url", "origin"): f"{origin}\n", + ("git", "symbolic-ref", "--short", "HEAD"): "item-7\n", + ("git", "rev-parse", "HEAD"): f"{HEAD}\n", + ("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"): "origin/main\n", + } + + def __call__(self, command: list[str]) -> str | Failure: + self.ran.append(command) + if command[2:3] == ["create"]: + self.open = True + if command == GH_LIST: + return f"12\t{HEAD}\tfalse\n" if self.open else "" + if command == TEA_LIST: + return json.dumps([{"number": 12, "head": {"ref": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else []) + return self.answers.get(tuple(command), "") + + def forge_calls(self) -> list[list[str]]: + """What it ran beyond reading the checkout and listing pull requests.""" + return [command for command in self.ran if tuple(command) not in self.answers and command not in (GH_LIST, TEA_LIST)] + + +class Open(unittest.TestCase): + def test_github_pushes_and_opens_a_draft_into_the_default_branch(self): + forge = Forge(GITHUB, open=False) + opened = step(["open", "ABC-1 - Do it", "The body."], forge) + self.assertEqual(forge.forge_calls(), [ + ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"], + ["gh", "pr", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "ABC-1 - Do it", "--body", "The body."], + ]) + self.assertEqual(opened, "Opened draft pull request #12.") + + def test_gitea_opens_a_draft_with_tea(self): + forge = Forge(GITEA, open=False) + step(["open", "Do it"], forge) + self.assertEqual(forge.forge_calls()[1], ["tea", "pulls", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "Do it", "--description", ""]) + + def test_an_open_pull_request_is_kept(self): + forge = Forge(GITEA, open=True) + self.assertEqual(step(["open", "Do it"], forge), "Pull request #12 is open already.") + self.assertEqual(forge.forge_calls(), [["git", "push", "--quiet", "--set-upstream", "origin", "item-7"]]) + + def test_a_title_of_more_than_one_line_is_refused_before_anything_runs(self): + forge = Forge(GITHUB, open=False) + self.assertIsInstance(step(["open", "Do it\nand more"], forge), Failure) + self.assertEqual(forge.ran, []) + + +class Ready(unittest.TestCase): + def test_github_marks_it_ready(self): + forge = Forge(GITHUB, open=True) + self.assertEqual(step(["ready"], forge), "Marked pull request #12 ready.") + self.assertEqual(forge.forge_calls(), [["gh", "pr", "ready", "12"]]) + + def test_gitea_drops_the_wip_prefix_with_tea(self): + forge = Forge(GITEA, open=True) + step(["ready"], forge) + self.assertEqual(forge.forge_calls(), [["tea", "pulls", "edit", "12", "--ready"]]) + + def test_without_an_open_pull_request_at_the_head_it_fails_naming_the_branch(self): + forge = Forge(GITHUB, open=False) + ready = step(["ready"], forge) + self.assertIsInstance(ready, Failure) + self.assertIn("item-7", ready.reason) + self.assertEqual(forge.forge_calls(), []) + + +class Merge(unittest.TestCase): + def test_without_the_gate_passed_it_refuses_before_anything_runs(self): + forge = Forge(GITHUB, open=True) + self.assertIsInstance(step(["merge"], forge), Failure) + self.assertEqual(forge.ran, []) + + def test_github_merges_pinned_to_the_head(self): + forge = Forge(GITHUB, open=True) + self.assertEqual(step(["merge", "--gate-passed"], forge), "Merged pull request #12.") + self.assertEqual(forge.forge_calls(), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]]) + + def test_gitea_merges_pinned_to_the_head(self): + forge = Forge(GITEA, open=True) + step(["merge", "--gate-passed"], forge) + self.assertEqual(forge.forge_calls(), [["tea", "api", "--method", "POST", "--field", "Do=merge", "--field", f"head_commit_id={HEAD}", "repos/{owner}/{repo}/pulls/12/merge"]]) + + def test_a_forge_failure_is_returned(self): + forge = Forge(GITHUB, open=True) + forge.answers[("gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD)] = Failure("gh pr merge: head moved") + self.assertEqual(step(["merge", "--gate-passed"], forge), Failure("gh pr merge: head moved")) + + +class Launcher(unittest.TestCase): + def test_help_exits_0_and_a_wrong_step_exits_1(self): + self.assertEqual(subprocess.run([str(TOOL), "--help"], capture_output=True, env=isolated_env()).returncode, 0) + wrong = subprocess.run([str(TOOL), "close"], capture_output=True, encoding="utf-8", env=isolated_env()) + self.assertEqual((wrong.returncode, wrong.stdout), (1, "")) + self.assertIn("usage", wrong.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/deploy_release/forge.py b/bin/deploy_release/forge.py index cd117aa9..22f3cd1b 100644 --- a/bin/deploy_release/forge.py +++ b/bin/deploy_release/forge.py @@ -1,4 +1,4 @@ -"""The pull request steps of a cut. They run gh where origin is on GitHub and tea elsewhere, as chunk_preflight tells the two apart. +"""The pull request steps of a cut, whose runner, gitea and open_pull chunk_pr shares. They run gh where origin is on GitHub and tea elsewhere, as chunk_preflight tells the two apart. Each step is pinned to head, the commit origin's release branch points at: the cut takes only a pull request from origin itself whose head is that commit, and the forge merges it only while its head is still that commit. So a fork's pull request from a branch of the same name, or a push to the branch after its checks passed, is never merged. """ diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 1f53cd65..f57e4686 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -7,7 +7,7 @@ description: Ship a work chunk through review to a merged PR; decisions land in You orchestrate, fix, and ship; reviewers only report. Run every reviewer in the foreground (`run_in_background: false`), each wave's reviewers in one message (ยง3 โ†’ "Waves"), and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until ยง6. -**Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. Resolve the tooling from the remote per `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs"; on any other forge, achieve the same intents through its CLI or API โ€” discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. +**Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. On GitHub and Gitea, `~/.claude/bin/chunk-pr` opens the draft, marks it ready and merges, and the remote picks the tooling for the other two, per `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". On any other forge, achieve all five through its CLI or API โ€” discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. The bar a chunk is reviewed to: ~/.claude/skills/larv-review/standards/quality.md. Words: `~/.claude/CLAUDE.md` โ†’ "Vocabulary". What a reviewer reports: ~/.claude/skills/larv-review/review-findings.md; how you resolve it: ยง3 โ†’ "Findings". @@ -22,7 +22,7 @@ The bar a chunk is reviewed to: ~/.claude/skills/larv-review/standards/quality.m ## 2. Ship the branch (idempotent โ€” skip whatever already exists) -Follow `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". Never commit to the default branch. Commit, push with upstream set, and open a **draft** PR so CI cycles while the review runs. No remote โ†’ review locally and say so in the summary. +Follow `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". Never commit to the default branch. Commit, then run `~/.claude/bin/chunk-pr open '<title>'`: it pushes with upstream set and opens a **draft** PR, so CI cycles while the review runs. No remote โ†’ review locally and say so in the summary. **Work in the worktree.** Enter the chunk's worktree with the `EnterWorktree` tool, `path` set to it, unless the session already works there. A reviewer, a seat and the security pass's skill read the diff of the session's working directory, and a subagent starts there; from the checkout root they find the branch's diff empty. @@ -186,14 +186,14 @@ Launch prose-reviewer with what the diff touched and every section this review c 3. Run the project's test suite locally unless the last stability round, or a later run, left the head verified green. 4. Watch the forge's checks until every one passes. A red check is a finding. 5. No CI configured โ†’ the gate is local tests only; note it in the summary. -6. Everything green โ†’ mark the PR ready, dropping any `WIP:`/`Draft:` title prefix. +6. Everything green โ†’ mark the PR ready with `~/.claude/bin/chunk-pr ready`. 7. **External auto-reviewer**, when the repo has one โ€” its config file (`.coderabbit.yaml` and the like), or its comments on earlier PRs; none โ†’ skip it, say so. Marking the PR ready is what summons it. Wait up to **10 minutes** for its first review, checking about once a minute; nothing by then โ†’ note it in the summary and carry on, never waiting twice. Its rounds, ยง3 โ†’ "Round cap". Once it has reviewed, each later return here before its cap, after a fix re-entered per ยง3, waits up to **5 minutes** for its re-review of the new commit. ## 5. Goal alignment, then merge 1. Read the finished PR against the README goals and code health, unless the README voids it: does anything in it work against one? It breaks a maintain goal โ†’ do not merge; redesign the change or drop its item. It works against an achieve goal โ†’ do not merge; ask the human, stating the conflict. 2. Run the comprehension check (ยง3) where it runs; it runs once. When `origin/<default branch>` moves after that, return to ยง4, and keep the ruling and scoring run already recorded. -3. Aligned, every pass done and everything green โ†’ **merge**. Follow the repo's merge method (`AGENTS.md`; ff-only where that is the convention). A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. +3. Aligned, every pass done and everything green โ†’ **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`. A repo whose `AGENTS.md` names another merge method, such as ff-only, merges that way through its forge instead. A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. 4. Merged โ†’ remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` โ†’ "Working loop". 5. Stop. The next chunk gets a fresh session. diff --git a/todo.md b/todo.md index 83e14490..b02f9165 100644 --- a/todo.md +++ b/todo.md @@ -14,7 +14,6 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 277 | 0.7.0 | | question | **Map the size of the code an item names onto S, on a scale the human picks, and have `score-outcomes` print that S for the item being scored and for each finished item it lists.** | 3 | 2 | 2 | 5 | 4 | 1.1 by 4, 1.4 by 3 | 2.4 | | 1 | 0.7.0 | | question | **Say in README โ†’ Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 1 | 2 | 1 | 2 | 1 | | 0.0 | -| 280 | 0.7.0 | | | **Open the chunk's pull request as a draft, mark it ready and merge it with one command per step that picks `tea` or `gh` from the remote, so no worker looks up `tea`'s or `gh`'s flags.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 4, 1.5 by 3 | 2.3 | | 282 | 0.7.0 | | | **Write the branch diff and what `larv-review places` prints into the chunk's review folder, and print each reviewer's prompt header, with one `larv-review` command.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 4, 1.5 by 3 | 2.3 | | 12 | 0.7.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 2.1 | | 285 | 0.7.0 | | | **Cut a worker's opens and searches of `todo.md` from the median 7 per chunk to at most 3, by finding in the last five chunks' archived transcripts what each read was for and removing its cause.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 4 | 1.6 | @@ -76,10 +75,6 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost The README line covers the bench's transcripts in `workflow-bench/logs/` too (goal 3). -### 280. Open the chunk's pull request as a draft, mark it ready and merge it with one command per step that picks `tea` or `gh` from the remote, so no worker looks up `tea`'s or `gh`'s flags. - -Audit of release 0.2.0's chunks (item 162): 37 chunks ran `tea pr` or `gh pr` create, ready, edit or merge, 106 calls, about 12.6k command tokens and 13.9k result tokens. 20 chunks spent 49 calls on `--help` lookups of those flags. The title follows `CLAUDE.md` โ†’ "Git, commits, and PRs"; the merge runs only where the caller says the gate passed. - ### 282. Write the branch diff and what `larv-review places` prints into the chunk's review folder, and print each reviewer's prompt header, with one `larv-review` command. Audit of release 0.2.0's chunks (item 162): 32 chunks wrote by hand the branch diff and what `larv-review places` prints, 92 calls, about 9.8k command tokens and 18k result tokens. 26 chunks launched 264 reviewers whose prompts were written by hand, 127k tokens in all, of which at least 10k are paths. The header names the pass, the round, the PR, the worktree, the branch, the base, and the paths of the reviewer's report, the diff and the places; the model adds the change summary. -- 2.52.0 From 6820946f2b5a0f9fc1e3a5462b6d845331f409e0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:04:43 +0100 Subject: [PATCH 3/8] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 7bd0b9a4469d4ab02a3a9d689ebc50812cb855f0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:14:12 +0100 Subject: [PATCH 4/8] =?UTF-8?q?Answer=20stability=20round=201:=202=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1=20(0=20misread);=20merge=20by?= =?UTF-8?q?=20the=20first=20method=20the=20repository=20allows,=20sort=20t?= =?UTF-8?q?he=20imports,=20keep=20'the=20cut'=20out=20of=20open=5Fpull's?= =?UTF-8?q?=20shared=20text,=20fake=20each=20forge=20apart=20and=20test=20?= =?UTF-8?q?the=20failed=20ready,=20listing=20and=20git=20calls;=20the=20de?= =?UTF-8?q?fault-branch=20refusal=20and=20help=20rewording,=20answering=20?= =?UTF-8?q?product-owner=20and=20prose,=20ride=20along?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/main.py | 69 +++++++++++----- bin/chunk_pr/test_chunk_pr.py | 147 +++++++++++++++++++++++----------- bin/deploy_release/forge.py | 6 +- 3 files changed, 151 insertions(+), 71 deletions(-) diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 9264586d..453988b0 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -4,31 +4,40 @@ usage: chunk-pr open <title> [<body>] chunk-pr ready chunk-pr merge --gate-passed -Run it in the chunk's worktree, on the chunk's branch. Each step acts on the open pull request from -origin's own branch of that name whose head is the commit checked out, so push before ready and merge. +Run it in the chunk's worktree, on the chunk's branch. ready and merge act on the branch's open +pull request only while its head is the commit checked out, so push before you run them. -open pushes the branch, setting its upstream, then opens a draft pull request into origin's - default branch, titled <title>: one line, as ~/.claude/CLAUDE.md โ†’ "Git, commits, and PRs" - says. Where that pull request is open already, it opens no other. -ready marks the pull request ready for review. Gitea has no draft state, so there it drops the - title's `WIP: ` prefix, which Gitea reads as a draft. -merge merges the pull request with a merge commit, and only while its head is still the commit - checked out, so a push after the gate is never merged. --gate-passed says the merge gate - passed on that commit; without it, chunk-pr refuses. A repo whose AGENTS.md names another - merge method merges through its forge instead. +open pushes the branch, setting its upstream, and opens a draft pull request into origin's + default branch. <title> is one line, as ~/.claude/CLAUDE.md โ†’ "Git, commits, and PRs" + says, and <body> is the pull request's summary. Where the branch's pull request is open + already, it opens no second one. On origin's default branch it refuses, pushing nothing. +ready marks the pull request ready for review. On Gitea a draft is a pull request whose title + starts with `WIP: `, so there it drops that prefix. +merge merges the pull request, and only while its head is still the commit checked out, so a + push after the gate is never merged. It takes the first method the repository allows of: + a merge commit, fast-forward only, a rebase followed by a merge commit, a rebase, a squash. + GitHub offers only the merge commit, the rebase and the squash. --gate-passed says the + merge gate passed on that commit; without it, chunk-pr refuses. -It prints the pull request's number, exit 0. A failure prints git's or the forge's reason, exit 1. +It prints what it did, exit 0, or why it failed, exit 1. """ +import json import os import sys -from chunk_preflight.choices import forge_of -from chunk_preflight.gathered import Forge -from deploy_release.forge import gitea, open_pull, Run, runner from failure import Failure +from chunk_preflight.gathered import Forge +from chunk_preflight.choices import forge_of +from deploy_release.forge import gitea, open_pull, Run, runner USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr ready | chunk-pr merge --gate-passed" +# Each forge's merge methods in the order merge prefers them, as the repository setting that allows the method and the method's name in the forge's merge call. A merge commit and a fast-forward keep the branch's commits as they are; a rebase or a squash rewrites them. +METHODS: dict[Forge, tuple[tuple[str, str], ...]] = { + "gh": (("mergeCommitAllowed", "--merge"), ("rebaseMergeAllowed", "--rebase"), ("squashMergeAllowed", "--squash")), + "tea": (("allow_merge_commits", "merge"), ("allow_fast_forward_only_merge", "fast-forward-only"), ("allow_rebase_explicit", "rebase-merge"), ("allow_rebase", "rebase"), ("allow_squash_merge", "squash")), +} + def main(argv: list[str]) -> int: if argv[:1] in (["-h"], ["--help"]): @@ -47,7 +56,7 @@ def step(argv: list[str], run: Run) -> str | Failure: match argv: case ["open", title, *body] if len(body) <= 1: if not title.strip() or "\n" in title: - return Failure("the title is one line of text") + return Failure("give a title of one line") return opened(title, body[0] if body else "", run) case ["ready"]: return marked_ready(run) @@ -89,6 +98,8 @@ def opened(title: str, body: str, run: Run) -> str | Failure: if isinstance(default, Failure): return Failure(f"origin records no default branch; set it with `git remote set-head origin --auto`: {default.reason}") base = default.strip().removeprefix("origin/") + if branch == base: + return Failure(f"{branch} is origin's default branch; open the pull request from the chunk's branch") pushed = run(["git", "push", "--quiet", "--set-upstream", "origin", branch]) if isinstance(pushed, Failure): return pushed @@ -121,9 +132,27 @@ def merged(run: Run) -> str | Failure: if isinstance(found, Failure): return found forge, number, head = found - # The forge refuses where the pull request's head has moved off head. + method = merge_method(forge, run) + if isinstance(method, Failure): + return method if forge == "gh": - done = run(["gh", "pr", "merge", number, "--merge", "--match-head-commit", head]) + done = run(["gh", "pr", "merge", number, method, "--match-head-commit", head]) else: - done = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", "Do=merge", f"head_commit_id={head}") - return done if isinstance(done, Failure) else f"Merged pull request #{number}." + done = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", f"Do={method}", f"head_commit_id={head}") + return done if isinstance(done, Failure) else f"Merged pull request #{number} ({method.removeprefix('--')})." + + +def merge_method(forge: Forge, run: Run) -> str | Failure: + """The first of METHODS[forge] that the repository's settings allow.""" + if forge == "gh": + viewed = run(["gh", "repo", "view", "--json", ",".join(setting for setting, _ in METHODS["gh"])]) + try: + settings = viewed if isinstance(viewed, Failure) else json.loads(viewed) + except ValueError: + return Failure(f"gh repo view printed no JSON: {str(viewed).strip()[:200]}") + else: + settings = gitea(run, "repos/{owner}/{repo}") + if isinstance(settings, Failure): + return settings + allowed = next((method for setting, method in METHODS[forge] if isinstance(settings, dict) and settings.get(setting) is True), None) + return allowed if allowed is not None else Failure(f"the repository allows none of the merge methods chunk-pr knows: {', '.join(method for _, method in METHODS[forge])}") diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index e735bbcd..83bf9d15 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -6,23 +6,30 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from chunk_pr.main import step from failure import Failure from test_env import isolated_env +from chunk_pr.main import step TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr" GITHUB = "git@github.com:me/project.git" GITEA = "ssh://git@gitea.example.org:22/me/project.git" HEAD = "c0ffee" +PUSH = ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"] GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,isCrossRepository", "--template", "{{range .}}{{.number}}\t{{.headRefOid}}\t{{.isCrossRepository}}\n{{end}}"] TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"] +GH_SETTINGS = ["gh", "repo", "view", "--json", "mergeCommitAllowed,rebaseMergeAllowed,squashMergeAllowed"] +TEA_SETTINGS = ["tea", "api", "repos/{owner}/{repo}"] -class Forge: - """A checkout on branch item-7 at HEAD, whose origin is origin and whose default branch is main. Pull request #12 from item-7 is open at HEAD where open says so, and once a create has run. It records every command run.""" +class Checkout: + """A fake run in a checkout of branch item-7 at commit HEAD, cloned from the GitHub or Gitea origin it is given, with main as origin's default branch. - def __init__(self, origin: str, open: bool): + Pull request #12 from item-7 is open at HEAD from the start where it is given open=True, and otherwise once a create has run. The repository allows the merge methods in allowed, by the forge's setting names: a merge commit unless given others. It records every command run, and fails the other forge's commands.""" + + def __init__(self, origin: str, open: bool, allowed: tuple[str, ...] = ("mergeCommitAllowed", "allow_merge_commits")): + self.github = origin == GITHUB self.open = open + self.allowed = allowed self.ran: list[list[str]] = [] self.answers: dict[tuple[str, ...], str | Failure] = { ("git", "remote", "get-url", "origin"): f"{origin}\n", @@ -33,84 +40,128 @@ class Forge: def __call__(self, command: list[str]) -> str | Failure: self.ran.append(command) + if command[0] == ("tea" if self.github else "gh"): + return Failure(f"{command[0]} on the wrong forge") + if tuple(command) in self.answers: + return self.answers[tuple(command)] if command[2:3] == ["create"]: self.open = True if command == GH_LIST: return f"12\t{HEAD}\tfalse\n" if self.open else "" if command == TEA_LIST: return json.dumps([{"number": 12, "head": {"ref": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else []) - return self.answers.get(tuple(command), "") + if command in (GH_SETTINGS, TEA_SETTINGS): + return json.dumps({setting: True for setting in self.allowed}) + return "" - def forge_calls(self) -> list[list[str]]: - """What it ran beyond reading the checkout and listing pull requests.""" - return [command for command in self.ran if tuple(command) not in self.answers and command not in (GH_LIST, TEA_LIST)] + def acted(self) -> list[list[str]]: + """What it ran beyond reading the checkout, the pull requests and the repository's settings.""" + reads = [GH_LIST, TEA_LIST, GH_SETTINGS, TEA_SETTINGS] + return [command for command in self.ran if tuple(command) not in self.answers and command not in reads] class Open(unittest.TestCase): def test_github_pushes_and_opens_a_draft_into_the_default_branch(self): - forge = Forge(GITHUB, open=False) - opened = step(["open", "ABC-1 - Do it", "The body."], forge) - self.assertEqual(forge.forge_calls(), [ - ["git", "push", "--quiet", "--set-upstream", "origin", "item-7"], - ["gh", "pr", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "ABC-1 - Do it", "--body", "The body."], - ]) + checkout = Checkout(GITHUB, open=False) + opened = step(["open", "ABC-1 - Do it", "The body."], checkout) + self.assertEqual(checkout.acted(), [PUSH, ["gh", "pr", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "ABC-1 - Do it", "--body", "The body."]]) self.assertEqual(opened, "Opened draft pull request #12.") def test_gitea_opens_a_draft_with_tea(self): - forge = Forge(GITEA, open=False) - step(["open", "Do it"], forge) - self.assertEqual(forge.forge_calls()[1], ["tea", "pulls", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "Do it", "--description", ""]) + checkout = Checkout(GITEA, open=False) + self.assertEqual(step(["open", "Do it"], checkout), "Opened draft pull request #12.") + self.assertEqual(checkout.acted(), [PUSH, ["tea", "pulls", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "Do it", "--description", ""]]) def test_an_open_pull_request_is_kept(self): - forge = Forge(GITEA, open=True) - self.assertEqual(step(["open", "Do it"], forge), "Pull request #12 is open already.") - self.assertEqual(forge.forge_calls(), [["git", "push", "--quiet", "--set-upstream", "origin", "item-7"]]) + checkout = Checkout(GITEA, open=True) + self.assertEqual(step(["open", "Do it"], checkout), "Pull request #12 is open already.") + self.assertEqual(checkout.acted(), [PUSH]) - def test_a_title_of_more_than_one_line_is_refused_before_anything_runs(self): - forge = Forge(GITHUB, open=False) - self.assertIsInstance(step(["open", "Do it\nand more"], forge), Failure) - self.assertEqual(forge.ran, []) + def test_on_the_default_branch_it_refuses_and_pushes_nothing(self): + checkout = Checkout(GITEA, open=False) + checkout.answers[("git", "symbolic-ref", "--short", "HEAD")] = "main\n" + self.assertIsInstance(step(["open", "Do it"], checkout), Failure) + self.assertEqual(checkout.acted(), []) + + def test_a_title_of_more_than_one_line_or_a_second_body_is_refused_before_anything_runs(self): + for argv in (["open", "Do it\nand more"], ["open", " "], ["open", "Do it", "Body", "More"]): + with self.subTest(argv): + checkout = Checkout(GITHUB, open=False) + self.assertIsInstance(step(argv, checkout), Failure) + self.assertEqual(checkout.ran, []) + + def test_a_failed_listing_after_the_create_is_returned(self): + checkout = Checkout(GITHUB, open=False) + checkout.answers[("gh", "pr", "create", "--draft", "--head", "item-7", "--base", "main", "--title", "Do it", "--body", "")] = Failure("gh pr create: done") + self.assertEqual(step(["open", "Do it"], checkout), Failure("gh pr create: done")) + checkout = Checkout(GITHUB, open=False) + listings = iter(["", Failure("gh pr list: offline")]) + original = checkout.__call__ + checkout_call = lambda command: next(listings) if command == GH_LIST else original(command) + self.assertEqual(step(["open", "Do it"], checkout_call), Failure("gh pr list: offline")) class Ready(unittest.TestCase): def test_github_marks_it_ready(self): - forge = Forge(GITHUB, open=True) - self.assertEqual(step(["ready"], forge), "Marked pull request #12 ready.") - self.assertEqual(forge.forge_calls(), [["gh", "pr", "ready", "12"]]) + checkout = Checkout(GITHUB, open=True) + self.assertEqual(step(["ready"], checkout), "Marked pull request #12 ready.") + self.assertEqual(checkout.acted(), [["gh", "pr", "ready", "12"]]) - def test_gitea_drops_the_wip_prefix_with_tea(self): - forge = Forge(GITEA, open=True) - step(["ready"], forge) - self.assertEqual(forge.forge_calls(), [["tea", "pulls", "edit", "12", "--ready"]]) + def test_gitea_marks_it_ready_with_tea(self): + checkout = Checkout(GITEA, open=True) + self.assertEqual(step(["ready"], checkout), "Marked pull request #12 ready.") + self.assertEqual(checkout.acted(), [["tea", "pulls", "edit", "12", "--ready"]]) def test_without_an_open_pull_request_at_the_head_it_fails_naming_the_branch(self): - forge = Forge(GITHUB, open=False) - ready = step(["ready"], forge) + checkout = Checkout(GITHUB, open=False) + ready = step(["ready"], checkout) self.assertIsInstance(ready, Failure) self.assertIn("item-7", ready.reason) - self.assertEqual(forge.forge_calls(), []) + self.assertEqual(checkout.acted(), []) + + def test_a_failed_ready_or_git_call_is_returned(self): + checkout = Checkout(GITEA, open=True) + checkout.answers[("tea", "pulls", "edit", "12", "--ready")] = Failure("tea pulls edit: denied") + self.assertEqual(step(["ready"], checkout), Failure("tea pulls edit: denied")) + checkout = Checkout(GITEA, open=True) + checkout.answers[("git", "symbolic-ref", "--short", "HEAD")] = Failure("git symbolic-ref: HEAD is detached") + self.assertEqual(step(["ready"], checkout), Failure("git symbolic-ref: HEAD is detached")) + self.assertEqual(checkout.acted(), []) class Merge(unittest.TestCase): def test_without_the_gate_passed_it_refuses_before_anything_runs(self): - forge = Forge(GITHUB, open=True) - self.assertIsInstance(step(["merge"], forge), Failure) - self.assertEqual(forge.ran, []) + checkout = Checkout(GITHUB, open=True) + self.assertIsInstance(step(["merge"], checkout), Failure) + self.assertEqual(checkout.ran, []) - def test_github_merges_pinned_to_the_head(self): - forge = Forge(GITHUB, open=True) - self.assertEqual(step(["merge", "--gate-passed"], forge), "Merged pull request #12.") - self.assertEqual(forge.forge_calls(), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]]) + def test_github_merges_with_a_merge_commit_pinned_to_the_head(self): + checkout = Checkout(GITHUB, open=True, allowed=("squashMergeAllowed", "mergeCommitAllowed")) + self.assertEqual(step(["merge", "--gate-passed"], checkout), "Merged pull request #12 (merge).") + self.assertEqual(checkout.acted(), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]]) - def test_gitea_merges_pinned_to_the_head(self): - forge = Forge(GITEA, open=True) - step(["merge", "--gate-passed"], forge) - self.assertEqual(forge.forge_calls(), [["tea", "api", "--method", "POST", "--field", "Do=merge", "--field", f"head_commit_id={HEAD}", "repos/{owner}/{repo}/pulls/12/merge"]]) + def test_github_without_merge_commits_rebases(self): + checkout = Checkout(GITHUB, open=True, allowed=("squashMergeAllowed", "rebaseMergeAllowed")) + step(["merge", "--gate-passed"], checkout) + self.assertEqual(checkout.acted(), [["gh", "pr", "merge", "12", "--rebase", "--match-head-commit", HEAD]]) + + def test_gitea_merges_fast_forward_only_where_only_that_and_squash_are_allowed(self): + checkout = Checkout(GITEA, open=True, allowed=("allow_squash_merge", "allow_fast_forward_only_merge")) + self.assertEqual(step(["merge", "--gate-passed"], checkout), "Merged pull request #12 (fast-forward-only).") + self.assertEqual(checkout.acted(), [["tea", "api", "--method", "POST", "--field", "Do=fast-forward-only", "--field", f"head_commit_id={HEAD}", "repos/{owner}/{repo}/pulls/12/merge"]]) + + def test_a_repository_allowing_no_known_method_is_refused_unmerged(self): + checkout = Checkout(GITEA, open=True, allowed=("allow_manual_merge",)) + self.assertIsInstance(step(["merge", "--gate-passed"], checkout), Failure) + self.assertEqual(checkout.acted(), []) def test_a_forge_failure_is_returned(self): - forge = Forge(GITHUB, open=True) - forge.answers[("gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD)] = Failure("gh pr merge: head moved") - self.assertEqual(step(["merge", "--gate-passed"], forge), Failure("gh pr merge: head moved")) + checkout = Checkout(GITHUB, open=True) + checkout.answers[("gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD)] = Failure("gh pr merge: head moved") + self.assertEqual(step(["merge", "--gate-passed"], checkout), Failure("gh pr merge: head moved")) + checkout = Checkout(GITHUB, open=True) + checkout.answers[tuple(GH_SETTINGS)] = "not json" + self.assertIsInstance(step(["merge", "--gate-passed"], checkout), Failure) class Launcher(unittest.TestCase): diff --git a/bin/deploy_release/forge.py b/bin/deploy_release/forge.py index 22f3cd1b..7b9c1198 100644 --- a/bin/deploy_release/forge.py +++ b/bin/deploy_release/forge.py @@ -1,4 +1,4 @@ -"""The pull request steps of a cut, whose runner, gitea and open_pull chunk_pr shares. They run gh where origin is on GitHub and tea elsewhere, as chunk_preflight tells the two apart. +"""The pull request steps of a cut. They run gh where origin is on GitHub and tea elsewhere, as chunk_preflight tells the two apart. Each step is pinned to head, the commit origin's release branch points at: the cut takes only a pull request from origin itself whose head is that commit, and the forge merges it only while its head is still that commit. So a fork's pull request from a branch of the same name, or a push to the branch after its checks passed, is never merged. """ @@ -51,14 +51,14 @@ def open_pull(forge: Forge, branch: str, head: str, run: Run) -> str | None | Fa return listed rows = [line.split("\t") for line in listed.splitlines()] return next((row[0] for row in rows if row[1:] == [head, "false"]), None) - # Gitea lists at most 50 a page; a release's pull request is among the newest. + # Gitea lists at most 50 a page; the pull request sought is among the newest. pulls = gitea(run, "repos/{owner}/{repo}/pulls?state=open&limit=50") if isinstance(pulls, Failure): return pulls try: return next((str(pull["number"]) for pull in pulls if pull["head"]["ref"] == branch and pull["head"]["sha"] == head and pull["head"]["repo"]["full_name"] == pull["base"]["repo"]["full_name"]), None) except (KeyError, TypeError): - return Failure(f"tea api listed pull requests in a shape the cut doesn't read: {str(pulls)[:200]}") + return Failure(f"tea api listed pull requests in a shape that can't be read: {str(pulls)[:200]}") def create_pull(forge: Forge, branch: str, base: str, title: str, run: Run) -> Failure | None: -- 2.52.0 From 797c5dd4fcea589b9370a61e89055cd685b72cbf Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:14:12 +0100 Subject: [PATCH 5/8] =?UTF-8?q?Answer=20product-owner=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20check=20chu?= =?UTF-8?q?nk-pr=20commands=20for=20an=20attribution;=20the=20default-bran?= =?UTF-8?q?ch=20refusal=20and=20the=20PR=20summary=20went=20in=20the=20sta?= =?UTF-8?q?bility=20and=20prose=20commits;=20tea's=20--draft=20and=20--rea?= =?UTF-8?q?dy=20are=20verified=20by=20its=20help=20and=20#448?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rule_hook/rules.py | 4 ++-- bin/rule_hook/test_rule_hook.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 636e7083..9d119eb0 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -45,7 +45,7 @@ RULES: dict[RuleName, Rule] = { ), "no-ai-attribution": Rule( "no commit, PR, issue comment or file carries a Claude or Anthropic attribution, such as a co-author trailer or a generated-with line", - "a git, gh or tea command, and any file written", + "a git, gh, tea or chunk-pr command, and any file written", ), # A Read carries no text for a marker, and a misjudged read has a way through that the message names, so no marker waives it. "repeat-read": Rule( @@ -140,7 +140,7 @@ def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> C def command_breaches(command: str, simples: list[Simple], home: str) -> list[Breach]: breaches = [] found = commits(simples, home) - publishing = [simple for simple in simples if simple.words[0] in ("gh", "git", "tea")] + publishing = [simple for simple in simples if posixpath.basename(simple.words[0]) in ("chunk-pr", "gh", "git", "tea")] if publishing and ATTRIBUTION.search(command): breaches.append(Breach("no-ai-attribution", "the command carries an attribution", publishing[0].directory)) for simple in simples: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index ded9dc2e..db283b15 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -133,8 +133,9 @@ class CommandBreaches(unittest.TestCase): with self.subTest(command): self.assertEqual(checked(command), []) - def test_an_attribution_breaks_only_in_a_git_gh_or_tea_command(self): + def test_an_attribution_breaks_only_in_a_git_gh_tea_or_chunk_pr_command(self): self.assertEqual(checked(f"tea pr create --description '{TRAILER}'"), ["no-ai-attribution"]) + self.assertEqual(checked(f"~/.claude/bin/chunk-pr open 'Do it' '{TRAILER}'"), ["no-ai-attribution"]) self.assertEqual(checked(f"grep -rn '{TRAILER}' ."), []) def test_a_commit_breach_names_the_commit_s_checkout(self): -- 2.52.0 From c26b5ab1ec64b886b4d2a9e1152a40d09c36fad8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:14:12 +0100 Subject: [PATCH 6/8] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1=20(0=20misread);=20reword=20th?= =?UTF-8?q?e=20skill's=20forge=20paragraph,=20the=20merge=20step=20and=20t?= =?UTF-8?q?he=20changelog,=20pass=20the=20summary=20to=20chunk-pr=20open,?= =?UTF-8?q?=20scope=20CLAUDE.md's=20line=20to=20GitHub=20and=20Gitea=20and?= =?UTF-8?q?=20sort=20the=20README's=20tools;=20the=20help=20fixes=20went?= =?UTF-8?q?=20in=20the=20stability=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- README.md | 4 ++-- skills/larv-review/SKILL.md | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c06717f9..47e686a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `chunk-pr open|ready|merge` opens a chunk's pull request as a draft, marks it ready and merges it, with `gh` or `tea` as the remote needs, and merges only when told the gate passed. `larv-review` and `CLAUDE.md` now use it. +- `chunk-pr open|ready|merge` opens a chunk's pull request as a draft, marks it ready and merges it, with `gh` or `tea` as the remote needs. It merges only with `--gate-passed`, by the first merge method the repository allows. `larv-review` and `CLAUDE.md` now tell workers to use it. - `score-outcomes` now gives, where most of the chunks it counts for L hold no ๐Ÿ”ด, the share of chunks with a ๐Ÿ”ด at each L in place of L's rank correlation by ๐Ÿ”ด findings. - `todo-item add` now files an item in `todo.md` with one command. It takes `Next ID` as the item's ID, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file. - `todo-item finish <ID>` now removes a finished item's row and detail from `todo.md`. With `--changelog <bullet>`, it also adds that bullet first under `CHANGELOG.md` โ†’ `## Unreleased`. Where a `CHANGELOG.md` exists, it refuses to run without `--changelog <bullet>` or `--no-changelog`, so no bullet is left out by mistake. diff --git a/CLAUDE.md b/CLAUDE.md index db3b0ea9..facbe471 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -95,7 +95,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - Branch for a ticket: exactly the ticket ID, nothing more. `ABC-123`, never `ABC-123-some-description`. - Branch for a `todo.md` item without a ticket: `item-<ID>`, in the worktree `<checkout>-item-<ID>` beside the checkout, as `chunk-preflight` makes them. - Use `gh` on GitHub remotes and `tea` on Gitea remotes (e.g. `gitea.larvit.se`) โ€” same command shape: `tea pr list|create`, `tea issue`, `tea release`, `tea api`. Everything in this section applies to both. -- Open a chunk's pull request as a draft, mark it ready and merge it with `~/.claude/bin/chunk-pr`, which picks `gh` or `tea` from the remote; `chunk-pr --help` says how. +- On GitHub and Gitea, open a chunk's pull request as a draft, mark it ready and merge it with `~/.claude/bin/chunk-pr`, which picks `gh` or `tea` from the remote; `chunk-pr --help` says how. ## Handoffs - Write no handoff document. The repo holds everything the next session needs: the plan, the decisions, and every script, sketch or measurement those depend on. A file outside the repo is unreachable from another machine's checkout. diff --git a/README.md b/README.md index c6ba7fba..bea52235 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,8 @@ It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that thro Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by their path, such as `~/.claude/bin/metric-bench`, from the project's checkout. Those under `~/.claude` are the release's; test a change to one from `~/code/claude-config/bin`. -- `chunk-preflight` finds the mechanical facts a chunk starts from, and with `--worktree` makes its worktree; `loop-claude` runs it with `--worktree` before it routes each chunk, and `chunk-preflight --help` lists the facts. - `chunk-pr open|ready|merge` opens a chunk's pull request as a draft, marks it ready and merges it, with `gh` on a GitHub origin and `tea` elsewhere; `chunk-pr --help` states the steps. +- `chunk-preflight` finds the mechanical facts a chunk starts from, and with `--worktree` makes its worktree; `loop-claude` runs it with `--worktree` before it routes each chunk, and `chunk-preflight --help` lists the facts. - `deploy-release [--cut] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says. - `judge-replay <model>` replays loop-claude's judge on archived verdicts of the projects run on the model, and prints the lowest rung that, like each rung above it, returns them; `judge-replay --help` states the replay. - `larv-review <command>` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count, the scoring run's trigger, and the comprehension history's format and latest places, and its count of how often seats agree; `larv-review --help` states them. @@ -130,8 +130,8 @@ Then, in the copy: `uvx --with pytest==9.2.0 'mutmut>=3,<4' run && uvx --with py `bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests. Beside the packages, `bin/`'s root holds only the launchers, the tools of one file with their tests, `test_env.py` and `failure.py`. `failure.py`'s `Failure`, which modules across `bin/` return for a failed step, belongs to no single package. `branch_chunks/`, `claude_code/`, `command_lines/`, `git_cli/`, `machine_load/`, `model_routing/`, `records/`, `release_plan/`, `review_rules/`, `rung_replay/` and `transcript_archive/` serve more than one tool. - `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path. -- `chunk_pr` imports `deploy_release`'s forge calls and `chunk_preflight`'s `forge_of`. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. +- `chunk_pr` imports `deploy_release`'s forge calls, and `forge_of` as `deploy_release` does. - `deploy_release` imports `chunk_preflight`'s `forge_of`, which tells a GitHub origin from a Gitea one, and `release_plan`'s `release_standing`. - `git_cli/` runs git for every tool (`git_repo.py`), and reads the git calls in a shell command (`git_command.py`). - `judge_replay` imports `loop_claude`'s judge. diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index f57e4686..ef6ac58d 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -7,7 +7,7 @@ description: Ship a work chunk through review to a merged PR; decisions land in You orchestrate, fix, and ship; reviewers only report. Run every reviewer in the foreground (`run_in_background: false`), each wave's reviewers in one message (ยง3 โ†’ "Waves"), and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until ยง6. -**Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. On GitHub and Gitea, `~/.claude/bin/chunk-pr` opens the draft, marks it ready and merges, and the remote picks the tooling for the other two, per `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". On any other forge, achieve all five through its CLI or API โ€” discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. +**Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. On GitHub and Gitea, `~/.claude/bin/chunk-pr` opens the draft PR, marks it ready and merges it. Read the diff and the checks with the forge's own CLI, `gh` or `tea` per `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". On any other forge, achieve all five through its CLI or API โ€” discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. The bar a chunk is reviewed to: ~/.claude/skills/larv-review/standards/quality.md. Words: `~/.claude/CLAUDE.md` โ†’ "Vocabulary". What a reviewer reports: ~/.claude/skills/larv-review/review-findings.md; how you resolve it: ยง3 โ†’ "Findings". @@ -22,7 +22,7 @@ The bar a chunk is reviewed to: ~/.claude/skills/larv-review/standards/quality.m ## 2. Ship the branch (idempotent โ€” skip whatever already exists) -Follow `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". Never commit to the default branch. Commit, then run `~/.claude/bin/chunk-pr open '<title>'`: it pushes with upstream set and opens a **draft** PR, so CI cycles while the review runs. No remote โ†’ review locally and say so in the summary. +Follow `~/.claude/CLAUDE.md` โ†’ "Git, commits, and PRs". Never commit to the default branch. Commit, then run `~/.claude/bin/chunk-pr open '<title>' '<summary>'`: it pushes with upstream set and opens a **draft** PR, so CI cycles while the review runs. No remote โ†’ review locally and say so in the summary. **Work in the worktree.** Enter the chunk's worktree with the `EnterWorktree` tool, `path` set to it, unless the session already works there. A reviewer, a seat and the security pass's skill read the diff of the session's working directory, and a subagent starts there; from the checkout root they find the branch's diff empty. @@ -193,7 +193,7 @@ Launch prose-reviewer with what the diff touched and every section this review c 1. Read the finished PR against the README goals and code health, unless the README voids it: does anything in it work against one? It breaks a maintain goal โ†’ do not merge; redesign the change or drop its item. It works against an achieve goal โ†’ do not merge; ask the human, stating the conflict. 2. Run the comprehension check (ยง3) where it runs; it runs once. When `origin/<default branch>` moves after that, return to ยง4, and keep the ruling and scoring run already recorded. -3. Aligned, every pass done and everything green โ†’ **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`. A repo whose `AGENTS.md` names another merge method, such as ff-only, merges that way through its forge instead. A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. +3. Aligned, every pass done and everything green โ†’ **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`, which takes the merge method the repository allows on its forge. A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. 4. Merged โ†’ remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` โ†’ "Working loop". 5. Stop. The next chunk gets a fresh session. -- 2.52.0 From 04a0ea384f283a2555621c61cb9fe89bf5553526 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:17:49 +0100 Subject: [PATCH 7/8] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20test=20a=20?= =?UTF-8?q?failed=20settings=20read=20on=20both=20forges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/chunk_pr/test_chunk_pr.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 83bf9d15..efa3189e 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -163,6 +163,14 @@ class Merge(unittest.TestCase): checkout.answers[tuple(GH_SETTINGS)] = "not json" self.assertIsInstance(step(["merge", "--gate-passed"], checkout), Failure) + def test_a_failed_settings_read_is_returned_unmerged(self): + for origin, settings in ((GITHUB, GH_SETTINGS), (GITEA, TEA_SETTINGS)): + with self.subTest(origin): + checkout = Checkout(origin, open=True) + checkout.answers[tuple(settings)] = Failure("settings: denied") + self.assertEqual(step(["merge", "--gate-passed"], checkout), Failure("settings: denied")) + self.assertEqual(checkout.acted(), []) + class Launcher(unittest.TestCase): def test_help_exits_0_and_a_wrong_step_exits_1(self): -- 2.52.0 From c1d485912c1b147977e6c1c791d1d35d905689ae Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv <lilleman@larvit.se> Date: Mon, 9 Nov 2026 02:17:49 +0100 Subject: [PATCH 8/8] =?UTF-8?q?Answer=20product-owner=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20let=20a=20m?= =?UTF-8?q?erge=20method=20AGENTS.md=20names=20win=20over=20chunk-pr's?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- skills/larv-review/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index ef6ac58d..3d2fc49b 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -193,7 +193,7 @@ Launch prose-reviewer with what the diff touched and every section this review c 1. Read the finished PR against the README goals and code health, unless the README voids it: does anything in it work against one? It breaks a maintain goal โ†’ do not merge; redesign the change or drop its item. It works against an achieve goal โ†’ do not merge; ask the human, stating the conflict. 2. Run the comprehension check (ยง3) where it runs; it runs once. When `origin/<default branch>` moves after that, return to ยง4, and keep the ruling and scoring run already recorded. -3. Aligned, every pass done and everything green โ†’ **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`, which takes the merge method the repository allows on its forge. A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. +3. Aligned, every pass done and everything green โ†’ **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`, which takes the first merge method the repository allows on its forge. A repo whose `AGENTS.md` names another method merges that way with the forge's CLI instead. A repo withholds this in its `AGENTS.md` โ†’ leave the PR ready and unmerged, and say which line withheld it. 4. Merged โ†’ remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` โ†’ "Working loop". 5. Stop. The next chunk gets a fresh session. -- 2.52.0