From 4b5086153a265d09cd243b35010ac47b9dc62f8e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:33:26 +0100 Subject: [PATCH 01/16] Make the Touches lists of items 303, 306, 287 and 387 readable: mark only named parts small --- todo.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/todo.md b/todo.md index 76798c2f..a9eeb980 100644 --- a/todo.md +++ b/todo.md @@ -89,7 +89,7 @@ Touches: - `bin/loop_claude/cycle/judge.py`: `run_judge`, `judge_once` - `bin/loop_claude/cycle/run.py`: `(module)` (small) - `bin/transcript_archive/write.py`: `archive`, `copy_for` -- `bin/transcript_archive/location.py` (small) +- `bin/transcript_archive/location.py` - `bin/transcript_archive/test_transcript_archive.py` - `bin/judge_replay/main.py`: `archived_cases`, `rule` - `bin/judge_replay/replay.py`: `case_from` @@ -111,8 +111,8 @@ Touches: - `bin/transcript_archive/write.py`: `copy_for`, `mirror` - `bin/transcript_archive/test_transcript_archive.py` - `bin/routing_figures/archive.py` -- `bin/reading_cost/main.py` (small) -- `bin/score_outcomes/reversals.py` (small) +- `bin/reading_cost/main.py` +- `bin/score_outcomes/reversals.py` - `bin/review_replay/rounds.py` - `bin/judge_replay/main.py`: `archived_cases` (small) - `skills/larv-review/SKILL.md`: `## 6. Wrap up` (small) @@ -153,9 +153,9 @@ Touches: - `bin/chunk_pr/approval.py`: `(module)` (small) - `bin/deploy_release/cut.py`: `(module)` (small) - `bin/larv_review/reviewer_header.py`: `(module)` (small) -- `bin/chunk_pr/test_chunk_pr.py` (small) -- `bin/chunk_preflight/test_chunk_preflight.py` (small) -- `bin/deploy_release/test_deploy_release.py` (small) +- `bin/chunk_pr/test_chunk_pr.py` +- `bin/chunk_preflight/test_chunk_preflight.py` +- `bin/deploy_release/test_deploy_release.py` ### 387. Bind a project's rung to its ladder in one value, so the routing functions and `Cycle` take one argument for both. @@ -168,14 +168,14 @@ Touches: - `bin/model_routing/ladder.py`: `Ladder` - `bin/loop_claude/routing.py` - `bin/loop_claude/cycle/run.py`: `Cycle` -- `bin/loop_claude/loop/main.py` (small) -- `bin/loop_claude/cycle/prompts.py` (small) -- `bin/loop_claude/loop/chunk_start.py` (small) -- `bin/loop_claude/loop/close.py` (small) -- `bin/loop_claude/escalation_mark.py` (small) -- `bin/model_routing/review_choice.py` (small) -- `bin/rule_hook/reviewer_rung.py` (small) -- `bin/judge_replay/main.py` (small) +- `bin/loop_claude/loop/main.py` +- `bin/loop_claude/cycle/prompts.py` +- `bin/loop_claude/loop/chunk_start.py` +- `bin/loop_claude/loop/close.py` +- `bin/loop_claude/escalation_mark.py` +- `bin/model_routing/review_choice.py` +- `bin/rule_hook/reviewer_rung.py` +- `bin/judge_replay/main.py` - `bin/loop_claude/test_loop_claude.py` ### 338. Script each step that 0.9.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release. From 3afbb554511c56a9e005593f44cecd6615d05015 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:40:13 +0100 Subject: [PATCH 02/16] Write no changelog bullet for a plan kept in Jira: todo-item finish there needs no changelog flag and refuses --changelog --- CLAUDE.md | 2 +- README.md | 2 +- bin/chunk_pr/main.py | 4 ++-- bin/todo_item/main.py | 12 ++++++++--- bin/todo_item/test_todo_item.py | 37 ++++++++++++++++++++++++++++++++- skills/larv-review/SKILL.md | 2 +- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 0698bf7a..6832601f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,7 +18,7 @@ How work proceeds in any repo, unless the repo's `AGENTS.md` says otherwise. The - **Ask, don't guess.** Three choices are always the human's: a goal; a release, meaning the items planned into it and when it is cut; and a change to loop-claude's routing ladder, its rungs included. Any other rule that asks the human's approval reserves that choice too. Ask about a reserved choice. For any other choice, first check whether the goals already answer it. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Otherwise take the option you would recommend, and record it with its reason: in the item's detail, or, where it governs later work, as the next sentence says. A recommendation you can give a reason for is not a guess. Ask only where you have no recommendation. Write every answer once, where it belongs, never only in chat: a goal in the goals file, a working rule in `AGENTS.md`, a standing choice in a comment at the one place it governs, or in `docs/decisions.md` once made in more than one place. When an answer holds a goal and a choice, write the goal in the goals file, and record as a choice only what the goal leaves open. - **Bench a syntax with the people who write it.** Before a new or changed spelling of something users read or write ships — markdown, HTML, a config key, a CLI flag — a panel of fresh-context readers, seated as those users from the goals file's `## Audience`, picks it. - **Implement the simplest change that solves the item, and ship it with `/larv-review`.** Whenever a test can check the change, write that test first and see it fail. Take its expected values from the item, never from the code. larv-review's reviewers hold the change to the technical principles, and a finding against one names it. Read a file in the principles folder the project's config sets (`~/.claude/bin/project-config principles` prints it) only when the item changes it, a finding or a record you write names it, or you decline a finding. -- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish ` removes the item with its detail, and adds the bullet you pass with `--changelog `; it refuses while a decision cites the item. A chunk finishes its items as it merges, through `chunk-pr merge --finish `, which takes the same flags (`larv-review` §5). +- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. A plan kept in Jira takes no bullet: the issues' history is its changelog, and `todo-item finish` there refuses `--changelog`. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish ` removes the item with its detail, and adds the bullet you pass with `--changelog `; it refuses while a decision cites the item. A chunk finishes its items as it merges, through `chunk-pr merge --finish `, which takes the same flags (`larv-review` §5). - **Releases are the human's.** The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision. - **Open each plan item or ticket with a bold one-sentence tagline**, so the taglines alone say what a release holds. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and doesn't say anything about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: `**Accept undefined in MetadataValue and drop such keys on output.**` BANNED: `MetadataValue accepts undefined; such keys are dropped on output`. - **File a security finding the moment it is found.** A security finding — a leaked credential, secret or PII, an auth bypass, an injection — goes under the next release, marked `security`, naming the exposure and the path it reaches. `~/.claude/bin/rank_todo.py` ranks it first in its release, after only the open questions, which wait for me. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will unmark it if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius. diff --git a/README.md b/README.md index a6af369c..3f65426f 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `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 on the project's routing ladder, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule. -- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show ` one item's row and detail; `add …` files an item under the next free ID, `edit …` sets an item's cells or detail, and `move --release ` sets an item's release; `finish ` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`. Each change ranks a markdown plan. `todo-item --help` states the flags. +- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show ` one item's row and detail; `add …` files an item under the next free ID, `edit …` sets an item's cells or detail, and `move --release ` sets an item's release; `finish ` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`, except for a plan kept in Jira, whose issues' history is its changelog. Each change ranks a markdown plan. `todo-item --help` states the flags. - `touch-predictions record ...` appends what a chunk's items were predicted to touch, under `Touches:` in their details, beside the files and parts its branch touched, to the record the config names as `touch-predictions`; `touch-predictions --help` shows the spelling and how a part is named. `chunk-preflight` reads the same predictions to name the items that may start chunks at once. - `wait-for [] [--timeout ]` waits until a file a background job writes holds a line matching the pattern, and prints it. diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 17dd9072..93075e38 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -29,8 +29,8 @@ merge merges the pull request in its turn: the chunks of one project on this turns, one at a time. Run it in the background. In its turn it: 1. fetches origin and merges its default branch into the branch, as sync does; 2. finishes each plan item a --finish names with `todo-item finish`, passing on - --changelog or --no-changelog, and commits what that changed in the plan and the - changelog, so both change only at merge time, on top of every chunk merged before; + --changelog or --no-changelog (a Jira plan takes no --changelog, as todo-item says), + and commits what that changed in the plan and the changelog, so both change only at merge time, on top of every chunk merged before; 3. pushes, also where step 2 failed after step 1 brought changes in; 4. waits for the pull request's checks, and those origin's default branch requires, to pass on the head; where no check reports within a minute, it takes the pull request diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index cde0c3ab..3b0a8443 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -63,7 +63,7 @@ mistake. It prints `Finished item in .` It doesn't write anything whi finish --no-changelog also drops an item no chunk built. In a Jira epic, finish doesn't remove anything: it moves the item's issue by the transition, and to the status, that the config's `jira-finish-transition` and `jira-finish-status` name, as -`project-config --help` shows. The --changelog rules hold there too, and docs/decisions.md isn't checked. +`project-config --help` shows. It needs neither --changelog nor --no-changelog (it accepts --no-changelog), never reads the changelog, and refuses --changelog, since the issues' history is the changelog. docs/decisions.md isn't checked. It fails, moving no issue, where the config sets neither, where the issue has no such transition from its present status, or where the transition leads to another status or to one Jira doesn't count as done. An issue that no chunk built is dropped in Jira, not with finish, which would mark it done. @@ -116,7 +116,8 @@ def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.T case "move": done = reported(plan.edit(args.id, {"Release": args.release}, None), "not moved", lambda written: f"Moved item {written.id} to release {args.release} in {plan.label}.") case _: - done = finish(args, plan, store(config, "changelog")) + # A Jira plan keeps no changelog: the issues' history in Jira says what shipped. + done = finish(args, plan, None if config.epic else store(config, "changelog")) if isinstance(done, Failure): print(done.reason, file=sys.stderr) return 1 @@ -217,7 +218,12 @@ def edit(args: argparse.Namespace, plan: PlanStore, text: str) -> str | Failure: return reported(plan.edit(args.id, fields(args), detail, args.comment), "not edited", lambda written: f"Edited item {written.id} in {plan.label}.") -def finish(args: argparse.Namespace, plan: PlanStore, changelog: RecordStore) -> str | Failure: +def finish(args: argparse.Namespace, plan: PlanStore, changelog: RecordStore | None) -> str | Failure: + """Finish item args.id in plan. changelog is where its bullet goes, or None where the plan keeps no changelog.""" + if changelog is None: + if args.changelog is not None: + return Failure("not finished: this plan keeps no changelog, since the issues' history is the changelog; drop --changelog") + return reported(plan.finish(args.id), "not finished", lambda written: f"Finished item {written.id} in {plan.label}.") held = changelog.held() if isinstance(held, Failure): return Failure(f"not finished: {held.reason}") diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index f63a798b..db35049b 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -4,10 +4,11 @@ import pathlib import sys import tempfile import unittest +import unittest.mock sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) -from project_config.test_project_config import configured +from project_config.test_project_config import configured, JIRA_PLAN, JIRA_SCORING from plan.test_ranking import DECISIONS, README, TODO from project_config.settings import DEFAULT_FLOOR from todo_item import edits, main @@ -266,6 +267,40 @@ class Finish(TodoItem): self.assertEqual(self.todo.read_text(), before) +class FinishInJira(TodoItem): + """A plan kept as a Jira epic keeps no changelog: the issues' history in Jira says what shipped.""" + + def setUp(self): + super().setUp() + self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', f'"{JIRA_PLAN}"') + 'env-file = "~/acme.env"\n' + JIRA_SCORING) + self.plan = MemoryPlan({3: {"Release": "0.1.0", "Item": "**Count the runs.**", "L": "1", "E": "2", "I": "3", "S": "1"}}) + patched = unittest.mock.patch.object(main, "plan_store", return_value=self.plan) + patched.start() + self.addCleanup(patched.stop) + + def test_finishes_without_either_flag_and_leaves_a_changelog_that_exists_alone(self): + self.changelog.write_text(CHANGELOG) + self.assertEqual(self.run_main("finish", "3"), (0, "Finished item 3 in the plan in memory.\n", "")) + self.assertEqual((self.plan.rows, self.changelog.read_text()), ({}, CHANGELOG)) + + def test_finishes_with_no_changelog_so_chunk_pr_merge_keeps_working(self): + self.changelog.write_text(CHANGELOG) + self.assertEqual(self.run_main("finish", "3", "--no-changelog"), (0, "Finished item 3 in the plan in memory.\n", "")) + self.assertEqual(self.changelog.read_text(), CHANGELOG) + + def test_refuses_a_bullet_writing_nothing_and_says_the_issues_history_is_the_changelog(self): + self.changelog.write_text(CHANGELOG) + code, out, err = self.run_main("finish", "3", "--changelog", "Runs are fast.") + self.assertEqual((code, out), (1, "")) + self.assertTrue(err.startswith("not finished: "), err) + self.assertIn("the issues' history is the changelog", err) + self.assertEqual((list(self.plan.rows), self.changelog.read_text()), ([3], CHANGELOG)) + + def test_doesnt_read_the_changelog(self): + self.changelog.write_bytes(b"# Changelog\n\n\xff\n") + self.assertEqual(self.run_main("finish", "3")[::2], (0, "")) + + class Show(TodoItem): def test_prints_the_header_the_row_and_the_detail(self): row = "| 3 | 0.1.0 | | | **Make it fast, `a \\| b`.** | 2 | 1 | 2 | 3 | 7 | 2.1 by 8, 1 by 6 |" diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 95861f69..023bb8bf 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -202,7 +202,7 @@ Launch prose-reviewer with what the diff touched and every section this review c 1. Read the finished PR against the goals file's goals and code health, unless that file 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. When `origin/` moves after that, return to §4, and keep the scoring run already recorded. Where the chunk recorded a paired ruling, run it again at the new head and record it: it read the head before the other chunk's merge came in. 3. Run `~/.claude/bin/touch-predictions record ...` in the worktree, naming the chunk's items: it records what they were predicted to touch beside what the branch touched, where the project's config names that record. A later pass through this step, after a return to §4, skips it. Commit and push it; the commit re-enters no pass. Leave the chunk's items in the plan, and write no changelog bullet in the branch: step 4 does both, so that `todo.md` and `CHANGELOG.md` never conflict between chunks. Revise any decision that cites an item now, since `todo-item finish` refuses while one does. -4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. Give it one `--finish ` per item the chunk ships, each with the arguments `todo-item finish` takes (`todo-item --help`), as in `chunk-pr merge --finish 12 --changelog '' --finish 13 --no-changelog`. The project's chunks merge one at a time. In its turn, `chunk-pr merge` merges `origin/` into the branch, finishes those items, pushes, and waits for the pull request's checks to pass; then it takes the first merge method the repository allows on its forge. Where it stops, do what it asks and run it again with the same arguments: +4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. Give it one `--finish ` per item the chunk ships, each with the arguments `todo-item finish` takes (`todo-item --help`), as in `chunk-pr merge --finish 12 --changelog '' --finish 13 --no-changelog`. Where the plan is a Jira epic, give no `--changelog`: the issues' history is the changelog, and `todo-item finish` there refuses a bullet. The project's chunks merge one at a time. In its turn, `chunk-pr merge` merges `origin/` into the branch, finishes those items, pushes, and waits for the pull request's checks to pass; then it takes the first merge method the repository allows on its forge. Where it stops, do what it asks and run it again with the same arguments: - **A merge conflict.** Resolve it, commit and push. Rerun only the passes whose triggers the resolution's own lines meet (§3), each in a round of its own. - **A paired ruling to run again.** `chunk-pr merge` has merged the default branch in and pushed. Run the ruling at that head, record it, commit and push. Don't return to §4 for it: the next turn waits for the checks at the new head. - **An owed scoring run, or a queue another pull request holds.** Record the run, or wait, as the message says. From 73600d7288448ef5946452573e21bcd172fb8821 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:42:01 +0100 Subject: [PATCH 03/16] Move the forge helpers into bin/forge/, which chunk_preflight, chunk_pr, deploy_release and larv_review import --- .gitignore | 2 + README.md | 6 +- bin/chunk_pr/approval.py | 3 +- bin/chunk_pr/main.py | 5 +- bin/chunk_pr/test_chunk_pr.py | 2 +- bin/chunk_preflight/choices.py | 6 +- bin/chunk_preflight/facts.py | 3 +- bin/chunk_preflight/gathered.py | 5 +- bin/chunk_preflight/main.py | 5 +- bin/chunk_preflight/test_chunk_preflight.py | 6 +- bin/deploy_release/cut.py | 19 ++--- bin/deploy_release/release_pull.py | 23 ++++++ bin/deploy_release/test_deploy_release.py | 59 +-------------- bin/forge/__init__.py | 1 + bin/forge/commands.py | 42 +++++++++++ .../forge.py => forge/pulls.py} | 58 ++------------ bin/forge/test_forge.py | 75 +++++++++++++++++++ bin/larv_review/reviewer_header.py | 4 +- 18 files changed, 179 insertions(+), 145 deletions(-) create mode 100644 bin/deploy_release/release_pull.py create mode 100644 bin/forge/__init__.py create mode 100644 bin/forge/commands.py rename bin/{deploy_release/forge.py => forge/pulls.py} (60%) create mode 100644 bin/forge/test_forge.py diff --git a/.gitignore b/.gitignore index 1e647053..94c1be88 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,8 @@ !bin/deploy_release/ !bin/deploy_release/*.py !bin/failure.py +!bin/forge/ +!bin/forge/*.py !bin/git_cli/ !bin/git_cli/*.py !bin/judge-replay diff --git a/README.md b/README.md index a6af369c..67188db2 100644 --- a/README.md +++ b/README.md @@ -194,14 +194,14 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `touch-predictions record ...` appends what a chunk's items were predicted to touch, under `Touches:` in their details, beside the files and parts its branch touched, to the record the config names as `touch-predictions`; `touch-predictions --help` shows the spelling and how a part is named. `chunk-preflight` reads the same predictions to name the items that may start chunks at once. - `wait-for [] [--timeout ]` waits until a file a background job writes holds a line matching the pattern, and prints it. -`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`, `failure.py` and `setup.cfg`. `failure.py`'s `Failure`, which modules across `bin/` return for a failed step, belongs to no single package. `atlassian/`, `branch_chunks/`, `claude_code/`, `command_lines/`, `git_cli/`, `loop_effects/`, `loop_state/`, `machine_load/`, `model_routing/`, `notifier/`, `plan/`, `plan_store/`, `record_store/`, `release_plan/`, `review_rules/`, `rung_replay/`, `text_files/` and `transcript_archive/` serve more than one tool. No package imports one that imports it back, which `repo_checks/test_package_cycles.py` checks. +`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`, `failure.py` and `setup.cfg`. `failure.py`'s `Failure`, which modules across `bin/` return for a failed step, belongs to no single package. `atlassian/`, `branch_chunks/`, `claude_code/`, `command_lines/`, `forge/`, `git_cli/`, `loop_effects/`, `loop_state/`, `machine_load/`, `model_routing/`, `notifier/`, `plan/`, `plan_store/`, `record_store/`, `release_plan/`, `review_rules/`, `rung_replay/`, `text_files/` and `transcript_archive/` serve more than one tool. No package imports one that imports it back, which `repo_checks/test_package_cycles.py` checks. - `adf_codec/` converts markdown to ADF, the rich text of Jira Cloud and Confluence, and back, in a throwaway container running a pinned `@larvit/adf-codec`. It builds the container's image inside a heavy slot. - `atlassian/` holds what the Jira and Confluence backends share (`client.py`): one Atlassian account's credentials, the request both backends send, and each service's error messages. - `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 `forge_of` as `deploy_release` does. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `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`. +- `deploy_release` imports `release_plan`'s `release_standing`. +- `forge/` tells a GitHub origin from a Gitea one and runs its CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review`. - `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, verdicts, premises and records. - `loop_claude` runs `chunk-preflight` as a process of its own. diff --git a/bin/chunk_pr/approval.py b/bin/chunk_pr/approval.py index a10118c8..a33b08e5 100644 --- a/bin/chunk_pr/approval.py +++ b/bin/chunk_pr/approval.py @@ -5,8 +5,7 @@ import time import typing from failure import Failure -from chunk_preflight.gathered import Forge -from deploy_release.forge import Run +from forge.commands import Forge, Run # A human answers in hours, so merge polls once a minute and gives up after 90 minutes. That leaves half an hour for the queue and the checks inside the 2 hours a background command may run; a run that needs more is killed before the give-up message prints, and its next run goes on from what it pushed. POLL_SECONDS = 60 diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 17dd9072..c4a7e747 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -85,10 +85,9 @@ import time import typing from chunk_pr.approval import approval, approved, awaited, unanswered -from deploy_release.forge import checks_passed, gitea, merged_pull, open_pull, required_checks, Run, runner +from forge.pulls import checks_passed, merged_pull, open_pull, required_checks from failure import Failure -from chunk_preflight.gathered import Forge -from chunk_preflight.choices import forge_of +from forge.commands import Forge, forge_of, gitea, Run, runner from project_config.main import located from project_config.settings import ProjectConfig from plan_store.plans import says_no_item diff --git a/bin/chunk_pr/test_chunk_pr.py b/bin/chunk_pr/test_chunk_pr.py index 79b886ea..a8ceafa1 100644 --- a/bin/chunk_pr/test_chunk_pr.py +++ b/bin/chunk_pr/test_chunk_pr.py @@ -15,7 +15,7 @@ from chunk_pr.main import cleaned, merged, QUEUE, step, turn, USAGE from failure import Failure from test_env import isolated_env from project_config.settings import ProjectConfig -from deploy_release.forge import Run +from forge.commands import Run from chunk_pr.approval import THREADS TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr" diff --git a/bin/chunk_preflight/choices.py b/bin/chunk_preflight/choices.py index b8a48c57..c3468b8a 100644 --- a/bin/chunk_preflight/choices.py +++ b/bin/chunk_preflight/choices.py @@ -1,7 +1,7 @@ """The pure choices the preflight's steps act on.""" import pathlib -from chunk_preflight.gathered import Forge +from forge.commands import Forge # The command each forge's CLI lists pull requests with; pulls_command adds the flags that pick their rows and fields. PULLS_LIST: dict[Forge, tuple[str, ...]] = {"gh": ("gh", "pr", "list"), "tea": ("tea", "pulls", "list")} @@ -26,10 +26,6 @@ def worktree_add(branch: str, path: pathlib.Path, default: str, local: bool, pus return ["worktree", "add", "--quiet", "--no-track", "-b", branch, str(path), default], f"added on the new branch {branch}, made off {default}." -def forge_of(origin_url: str) -> Forge: - return "gh" if "github.com" in origin_url else "tea" - - def pulls_command(forge: Forge, branch: str) -> list[str]: """The command that lists open pull requests: gh only branch's, by number and URL; tea every one, by index, head and URL, for facts.open_pulls to pick branch's.""" if forge == "gh": diff --git a/bin/chunk_preflight/facts.py b/bin/chunk_preflight/facts.py index 33f8c3ba..f99ea8cf 100644 --- a/bin/chunk_preflight/facts.py +++ b/bin/chunk_preflight/facts.py @@ -4,7 +4,8 @@ from touch_predictions.beside import chunks_beside from release_plan.next_chunk import cut_name, NextChunk, NoItem from release_plan.release_standing import dated_cut, LastCut, unreleased_entries, UNSEEN_RELEASES from failure import Failure -from chunk_preflight.gathered import Forge, Gathered, ItemFacts, NamedPath, Ran +from forge.commands import Forge +from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, Ran from text_files.markdown_text import listed, quoted from chunk_preflight.choices import PULLS_LIST from plan.release import version diff --git a/bin/chunk_preflight/gathered.py b/bin/chunk_preflight/gathered.py index 0656e15e..ba81bdbe 100644 --- a/bin/chunk_preflight/gathered.py +++ b/bin/chunk_preflight/gathered.py @@ -1,15 +1,12 @@ """What the preflight gathers, which facts.render states.""" import dataclasses import pathlib -import typing from failure import Failure +from forge.commands import Forge from release_plan.release_standing import LastCut from release_plan.next_chunk import NextChunk, NoItem -# The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other. -Forge = typing.Literal["gh", "tea"] - @dataclasses.dataclass(frozen=True) class Ran: diff --git a/bin/chunk_preflight/main.py b/bin/chunk_preflight/main.py index c1490a77..daeb8a96 100644 --- a/bin/chunk_preflight/main.py +++ b/bin/chunk_preflight/main.py @@ -78,13 +78,14 @@ import typing from git_cli.git_repo import commit_exists, default_branch, file_at, git, top from failure import Failure -from chunk_preflight.gathered import Forge, Gathered, ItemFacts, NamedPath, Ran, Worktree -from chunk_preflight.choices import forge_of, pulls_command, worktree_add, worktree_on +from forge.commands import Forge, forge_of +from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, Ran, Worktree from chunk_preflight.facts import JOINING_DETAILS, render from project_config.main import located from plan.named_paths import named_paths from release_plan.next_chunk import NextChunk, NoItem, plan_name, planned from release_plan.release_standing import project_plan +from chunk_preflight.choices import pulls_command, worktree_add, worktree_on BIN = pathlib.Path(__file__).resolve().parents[1] # Each tool run in the item's worktree, {item} standing for the item's ID. diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index 5157f150..545cede4 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -13,7 +13,6 @@ from project_config.templates import BRANCH from release_plan.next_chunk import CarriedOver, NoItem from chunk_preflight import choices from failure import Failure -from chunk_preflight.choices import forge_of, worktree_add from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, Ran, Worktree from test_env import isolated_env from release_plan.release_standing import LastCut, UNSEEN_RELEASES @@ -21,6 +20,7 @@ from chunk_preflight.main import line_count, ran, seconds, TIMEOUT from release_plan import next_chunk from chunk_preflight.facts import open_pulls, render from plan_store.todo_md import plan_of +from chunk_preflight.choices import worktree_add from project_config.test_project_config import write_config BIN = pathlib.Path(__file__).resolve().parents[1] @@ -653,10 +653,6 @@ class Gathering(unittest.TestCase): self.assertEqual(worktree_add("item-3", path, "origin/main", False, True)[0], ["worktree", "add", "--quiet", "--track", "-b", "item-3", "/c/proj-item-3", "origin/item-3"]) self.assertEqual(worktree_add("item-3", path, "origin/main", False, False)[0], ["worktree", "add", "--quiet", "--no-track", "-b", "item-3", "/c/proj-item-3", "origin/main"]) - def test_lists_pull_requests_with_gh_on_a_github_origin_and_with_tea_elsewhere(self): - self.assertEqual(forge_of("git@github.com:o/r.git"), "gh") - self.assertEqual(forge_of("https://gitea.larvit.se/o/r.git"), "tea") - def test_reads_the_timeout_setting_as_seconds_above_0_and_else_takes_the_default(self): self.assertEqual(seconds(None), TIMEOUT) self.assertEqual(seconds("2.5"), 2.5) diff --git a/bin/deploy_release/cut.py b/bin/deploy_release/cut.py index c39a8fd6..b764bfbd 100644 --- a/bin/deploy_release/cut.py +++ b/bin/deploy_release/cut.py @@ -14,9 +14,10 @@ from deploy_release.deploy import deploy from failure import Failure from plan_store.todo_md import FilePlan from record_store.stores import FileStore -from deploy_release import forge -from chunk_preflight.choices import forge_of +from forge.commands import forge_of, runner from plan.release import newest_tag, Release, UNRELEASED_HEADING, version +from forge import pulls +from deploy_release import release_pull from project_config import templates @@ -153,7 +154,7 @@ def land(clone: str, ref: str, named: str, title: str) -> Failure | None: url = git("config", "--get", "remote.origin.url", cwd=clone) if isinstance(url, Failure): return url - on, run, branch, base = forge_of(url), forge.runner(clone), f"release-{named}", ref.removeprefix("origin/") + on, run, branch, base = forge_of(url), runner(clone), f"release-{named}", ref.removeprefix("origin/") head = branch_head(branch, clone) if isinstance(head, Failure): return head @@ -168,23 +169,23 @@ def land(clone: str, ref: str, named: str, title: str) -> Failure | None: head = branch_head(branch, clone) or Failure(f"pushed {branch}, but origin holds no such branch") if isinstance(head, Failure): return head - number = forge.open_pull(on, branch, head, run) + number = pulls.open_pull(on, branch, head, run) if number is None: - if isinstance(created := forge.create_pull(on, branch, base, title, run), Failure): + if isinstance(created := release_pull.create_pull(on, branch, base, title, run), Failure): return created - number = forge.open_pull(on, branch, head, run) or Failure(f"opened a pull request for {branch}, but the forge lists none from origin at {head[:12]}") + number = pulls.open_pull(on, branch, head, run) or Failure(f"opened a pull request for {branch}, but the forge lists none from origin at {head[:12]}") if isinstance(number, str): said(f"opened pull request {number}") if isinstance(number, Failure): return number - required = forge.required_checks(on, base, run) + required = pulls.required_checks(on, base, run) if isinstance(required, Failure): return required said(f"waiting for the checks of pull request {number}" + (f"; {base} requires {', '.join(sorted(required))}" if required else "")) - if isinstance(passed := forge.checks_passed(on, number, head, required, run), Failure): + if isinstance(passed := pulls.checks_passed(on, number, head, required, run), Failure): return passed said(f"the checks of pull request {number} passed") - if isinstance(merged := forge.merge(on, number, head, run), Failure): + if isinstance(merged := release_pull.merge(on, number, head, run), Failure): return merged said(f"merged pull request {number}") return None diff --git a/bin/deploy_release/release_pull.py b/bin/deploy_release/release_pull.py new file mode 100644 index 00000000..fa2ae8ef --- /dev/null +++ b/bin/deploy_release/release_pull.py @@ -0,0 +1,23 @@ +"""The pull request steps of a cut. They run gh where origin is on GitHub and tea elsewhere, as `forge.commands` 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. +""" +from failure import Failure +from forge.commands import Forge, gitea, Run + + +def create_pull(forge: Forge, branch: str, base: str, title: str, run: Run) -> Failure | None: + body = ["--body" if forge == "gh" else "--description", "Rename ## Unreleased in CHANGELOG.md to the version."] + command = ["gh", "pr"] if forge == "gh" else ["tea", "pulls"] + created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *body]) + return created if isinstance(created, Failure) else None + + +def merge(forge: Forge, number: str, head: str, run: Run) -> Failure | None: + """Merge pull request number, fast-forward only on Gitea and by rebase on GitHub. The forge refuses where the pull request's head is no longer head.""" + if forge == "gh": + # GitHub has no fast-forward-only merge. A rebase merge of a branch already on top of main is the nearest, though it may give the commit a new hash, so the cut finds it on main by its title. + merged = run(["gh", "pr", "merge", number, "--rebase", "--match-head-commit", head]) + else: + merged = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", "Do=fast-forward-only", f"head_commit_id={head}") + return merged if isinstance(merged, Failure) else None diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index e91321c3..851a1487 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -1,16 +1,13 @@ -import itertools import json import os import pathlib import subprocess import sys import tempfile -import typing import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from deploy_release.forge import checks_passed, POLL_SECONDS, required_checks, WAIT_SECONDS from failure import Failure from test_env import isolated_env @@ -229,6 +226,10 @@ save() """.replace("PYTHON", sys.executable) +# The protection of main that requires CI's check. +REQUIRED = '{"name": "main", "enable_status_check": true, "status_check_contexts": ["CI / tests (pull_request)"]}' + + class Cut(unittest.TestCase): """A development clone whose next release, 0.2.0, holds no item, has its release review landed and one change unreleased; and a ~/.claude on v0.1.0.""" @@ -486,58 +487,6 @@ class Cut(unittest.TestCase): self.assertEqual(self.origin_git("log", "-1", "--format=%s", "main").strip(), "Release review of 0.2.0") -def tea(statuses: typing.Iterable[str], branch: str = '{"name": "main"}') -> typing.Callable[[list[str]], str]: - """A tea answering each read of the head's status with the next of statuses, and of branch main with branch.""" - answers = iter(statuses) - return lambda command: branch if command[-1] == "repos/{owner}/{repo}/branches/main" else next(answers) - - -REQUIRED = '{"name": "main", "enable_status_check": true, "status_check_contexts": ["CI / tests (pull_request)"]}' - - -class RequiredChecks(unittest.TestCase): - def test_reads_on_tea_the_checks_the_protection_of_the_base_requires(self): - self.assertEqual(required_checks("tea", "main", tea([], REQUIRED)), {"CI / tests (pull_request)"}) - - def test_reads_none_on_tea_where_the_protection_turns_status_checks_off(self): - self.assertEqual(required_checks("tea", "main", tea([], '{"name": "main", "enable_status_check": false, "status_check_contexts": ["CI / tests (pull_request)"]}')), set()) - - def test_fails_on_tea_where_the_branch_reads_in_another_shape(self): - self.assertIsInstance(required_checks("tea", "main", tea([], "[]")), Failure) - - def test_reads_none_on_github_whose_watch_covers_them(self): - self.assertEqual(required_checks("gh", "main", self.fail), set()) - - -class ChecksPassed(unittest.TestCase): - def test_waits_on_tea_while_a_check_is_pending(self): - slept = [] - self.assertIsNone(checks_passed("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 1}', '{"state": "success", "total_count": 1}']), slept.append)) - self.assertEqual(slept, [POLL_SECONDS]) - - def test_takes_a_commit_with_no_status_on_tea_as_passed_where_the_base_requires_none(self): - self.assertIsNone(checks_passed("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 0}']), self.fail)) - - def test_waits_on_tea_for_a_check_the_base_requires_until_it_reports_and_passes(self): - slept = [] - statuses = ['{"state": "pending", "total_count": 0, "statuses": []}', '{"state": "success", "total_count": 1, "statuses": [{"context": "lint", "status": "success"}]}', '{"state": "success", "total_count": 2, "statuses": [{"context": "lint", "status": "success"}, {"context": "CI / tests (pull_request)", "status": "success"}]}'] - self.assertIsNone(checks_passed("tea", "1", "abc", {"CI / tests (pull_request)"}, tea(statuses), slept.append)) - self.assertEqual(slept, [POLL_SECONDS, POLL_SECONDS]) - - def test_takes_on_tea_a_required_glob_as_met_by_a_check_it_matches(self): - passed = '{"state": "success", "total_count": 1, "statuses": [{"context": "CI / tests (pull_request)", "status": "success"}]}' - self.assertIsNone(checks_passed("tea", "1", "abc", {"CI / *"}, tea([passed]), self.fail)) - - def test_gives_up_on_tea_after_the_wait_naming_a_required_check_that_never_reported(self): - slept = [] - waited = checks_passed("tea", "1", "abc", {"CI / tests (pull_request)"}, tea(itertools.repeat('{"state": "pending", "total_count": 0, "statuses": []}')), slept.append) - self.assertIsInstance(waited, Failure) - self.assertIn("CI / tests (pull_request)", waited.reason) - self.assertEqual(sum(slept), WAIT_SECONDS) - - def test_fails_on_tea_where_a_check_failed(self): - self.assertIsInstance(checks_passed("tea", "1", "abc", set(), tea(['{"state": "failure", "total_count": 1}']), self.fail), Failure) - if __name__ == "__main__": unittest.main() diff --git a/bin/forge/__init__.py b/bin/forge/__init__.py new file mode 100644 index 00000000..46a2dc1a --- /dev/null +++ b/bin/forge/__init__.py @@ -0,0 +1 @@ +"""The forge a checkout's origin is on, GitHub or Gitea, and the calls to it that several tools make: `commands.py` tells the two apart and runs their CLIs, `pulls.py` finds a pull request and waits for its checks.""" diff --git a/bin/forge/commands.py b/bin/forge/commands.py new file mode 100644 index 00000000..c74168f4 --- /dev/null +++ b/bin/forge/commands.py @@ -0,0 +1,42 @@ +"""Which forge a checkout's origin is on, and running that forge's CLI in the checkout.""" +import json +import subprocess +import typing + +from failure import Failure + +# The CLI that talks to a forge: gh for a github.com origin, tea for any other. +Forge = typing.Literal["gh", "tea"] + +# Runs a command in the clone: what it printed, or a Failure with its reason. +Run = typing.Callable[[list[str]], str | Failure] + + +def forge_of(origin_url: str) -> Forge: + return "gh" if "github.com" in origin_url else "tea" + + +def runner(cwd: str) -> Run: + def run(command: list[str]) -> str | Failure: + try: + done = subprocess.run(command, capture_output=True, cwd=cwd, encoding="utf-8", errors="replace", stdin=subprocess.DEVNULL) + except OSError as failure: + return Failure(f"{command[0]} could not start: {failure}") + if done.returncode: + return Failure(f"{' '.join(command[:3])}: {(done.stderr or done.stdout).strip()}") + return done.stdout + return run + + +def gitea(run: Run, endpoint: str, *fields: str) -> typing.Any | Failure: + """What Gitea's API answered at endpoint, parsed; with fields, `key=value` strings, a POST of them. tea api exits 0 on an HTTP error too, so an answer with Gitea's `message` key is a Failure.""" + answered = run(["tea", "api", *(["--method", "POST"] if fields else []), *[word for field in fields for word in ("--field", field)], endpoint]) + if isinstance(answered, Failure) or not answered.strip(): + return answered + try: + parsed = json.loads(answered) + except ValueError: + return Failure(f"tea api {endpoint} printed no JSON: {answered.strip()[:200]}") + if isinstance(parsed, dict) and "message" in parsed: + return Failure(f"tea api {endpoint}: {parsed['message']}") + return parsed diff --git a/bin/deploy_release/forge.py b/bin/forge/pulls.py similarity index 60% rename from bin/deploy_release/forge.py rename to bin/forge/pulls.py index 047a5ae1..639b2336 100644 --- a/bin/deploy_release/forge.py +++ b/bin/forge/pulls.py @@ -1,50 +1,19 @@ -"""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. +"""Finding a pull request from origin's own branch, and waiting for its checks. -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. +Each call is pinned to head, a commit on that branch: it takes only a pull request from origin itself whose head is that commit. So a fork's pull request from a branch of the same name is never taken. """ import fnmatch -import json -import subprocess import time import typing from failure import Failure -from chunk_preflight.choices import Forge +from forge.commands import Forge, gitea, Run -# How long the cut waits between two reads of the head commit's status on Gitea. +# How long checks_passed waits between two reads of the head commit's status on Gitea. POLL_SECONDS = 10 -# How long the cut waits for the checks before it gives up; CI took about 3 minutes in 2026-11. +# How long checks_passed waits for the checks before it gives up; CI took about 3 minutes in 2026-11. WAIT_SECONDS = 30 * 60 -# Runs a command in the clone: what it printed, or a Failure with its reason. -Run = typing.Callable[[list[str]], str | Failure] - - -def runner(cwd: str) -> Run: - def run(command: list[str]) -> str | Failure: - try: - done = subprocess.run(command, capture_output=True, cwd=cwd, encoding="utf-8", errors="replace", stdin=subprocess.DEVNULL) - except OSError as failure: - return Failure(f"{command[0]} could not start: {failure}") - if done.returncode: - return Failure(f"{' '.join(command[:3])}: {(done.stderr or done.stdout).strip()}") - return done.stdout - return run - - -def gitea(run: Run, endpoint: str, *fields: str) -> typing.Any | Failure: - """What Gitea's API answered at endpoint, parsed; with fields, `key=value` strings, a POST of them. tea api exits 0 on an HTTP error too, so an answer with Gitea's `message` key is a Failure.""" - answered = run(["tea", "api", *(["--method", "POST"] if fields else []), *[word for field in fields for word in ("--field", field)], endpoint]) - if isinstance(answered, Failure) or not answered.strip(): - return answered - try: - parsed = json.loads(answered) - except ValueError: - return Failure(f"tea api {endpoint} printed no JSON: {answered.strip()[:200]}") - if isinstance(parsed, dict) and "message" in parsed: - return Failure(f"tea api {endpoint}: {parsed['message']}") - return parsed - def open_pull(forge: Forge, branch: str, head: str, run: Run) -> str | None | Failure: """The number of the open pull request from origin's own branch whose head is head; None where there is none.""" @@ -75,13 +44,6 @@ def pull_at(forge: Forge, branch: str, head: str, state: typing.Literal["open", 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: - body = ["--body" if forge == "gh" else "--description", "Rename ## Unreleased in CHANGELOG.md to the version."] - command = ["gh", "pr"] if forge == "gh" else ["tea", "pulls"] - created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *body]) - return created if isinstance(created, Failure) else None - - def required_checks(forge: Forge, base: str, run: Run) -> set[str] | Failure: """The checks, or glob patterns of checks, that the forge's protection of the branch base requires before a merge. None on GitHub, where gh's watch covers them. @@ -132,13 +94,3 @@ def checks_passed(forge: Forge, number: str, head: str, required: set[str], run: sleep(POLL_SECONDS) waited_on = f"{', '.join(missing)}, which the protection requires, never passed" if missing else "a check is still pending" return Failure(f"gave up on pull request {number} after {WAIT_SECONDS // 60} minutes: {waited_on}") - - -def merge(forge: Forge, number: str, head: str, run: Run) -> Failure | None: - """Merge pull request number, fast-forward only on Gitea and by rebase on GitHub. The forge refuses where the pull request's head is no longer head.""" - if forge == "gh": - # GitHub has no fast-forward-only merge. A rebase merge of a branch already on top of main is the nearest, though it may give the commit a new hash, so the cut finds it on main by its title. - merged = run(["gh", "pr", "merge", number, "--rebase", "--match-head-commit", head]) - else: - merged = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", "Do=fast-forward-only", f"head_commit_id={head}") - return merged if isinstance(merged, Failure) else None diff --git a/bin/forge/test_forge.py b/bin/forge/test_forge.py new file mode 100644 index 00000000..9b72aafe --- /dev/null +++ b/bin/forge/test_forge.py @@ -0,0 +1,75 @@ +import itertools +import pathlib +import sys +import typing +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from forge.pulls import checks_passed, POLL_SECONDS, required_checks, WAIT_SECONDS +from failure import Failure +from forge.commands import forge_of + + +class ForgeOf(unittest.TestCase): + def test_takes_a_github_origin_as_gh_and_any_other_as_tea(self): + self.assertEqual(forge_of("git@github.com:o/r.git"), "gh") + self.assertEqual(forge_of("https://gitea.larvit.se/o/r.git"), "tea") + + +def tea(statuses: typing.Iterable[str], branch: str = '{"name": "main"}') -> typing.Callable[[list[str]], str]: + """A tea answering each read of the head's status with the next of statuses, and of branch main with branch.""" + answers = iter(statuses) + return lambda command: branch if command[-1] == "repos/{owner}/{repo}/branches/main" else next(answers) + + +REQUIRED = '{"name": "main", "enable_status_check": true, "status_check_contexts": ["CI / tests (pull_request)"]}' + + +class RequiredChecks(unittest.TestCase): + def test_reads_on_tea_the_checks_the_protection_of_the_base_requires(self): + self.assertEqual(required_checks("tea", "main", tea([], REQUIRED)), {"CI / tests (pull_request)"}) + + def test_reads_none_on_tea_where_the_protection_turns_status_checks_off(self): + self.assertEqual(required_checks("tea", "main", tea([], '{"name": "main", "enable_status_check": false, "status_check_contexts": ["CI / tests (pull_request)"]}')), set()) + + def test_fails_on_tea_where_the_branch_reads_in_another_shape(self): + self.assertIsInstance(required_checks("tea", "main", tea([], "[]")), Failure) + + def test_reads_none_on_github_whose_watch_covers_them(self): + self.assertEqual(required_checks("gh", "main", self.fail), set()) + + +class ChecksPassed(unittest.TestCase): + def test_waits_on_tea_while_a_check_is_pending(self): + slept = [] + self.assertIsNone(checks_passed("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 1}', '{"state": "success", "total_count": 1}']), slept.append)) + self.assertEqual(slept, [POLL_SECONDS]) + + def test_takes_a_commit_with_no_status_on_tea_as_passed_where_the_base_requires_none(self): + self.assertIsNone(checks_passed("tea", "1", "abc", set(), tea(['{"state": "pending", "total_count": 0}']), self.fail)) + + def test_waits_on_tea_for_a_check_the_base_requires_until_it_reports_and_passes(self): + slept = [] + statuses = ['{"state": "pending", "total_count": 0, "statuses": []}', '{"state": "success", "total_count": 1, "statuses": [{"context": "lint", "status": "success"}]}', '{"state": "success", "total_count": 2, "statuses": [{"context": "lint", "status": "success"}, {"context": "CI / tests (pull_request)", "status": "success"}]}'] + self.assertIsNone(checks_passed("tea", "1", "abc", {"CI / tests (pull_request)"}, tea(statuses), slept.append)) + self.assertEqual(slept, [POLL_SECONDS, POLL_SECONDS]) + + def test_takes_on_tea_a_required_glob_as_met_by_a_check_it_matches(self): + passed = '{"state": "success", "total_count": 1, "statuses": [{"context": "CI / tests (pull_request)", "status": "success"}]}' + self.assertIsNone(checks_passed("tea", "1", "abc", {"CI / *"}, tea([passed]), self.fail)) + + def test_gives_up_on_tea_after_the_wait_naming_a_required_check_that_never_reported(self): + slept = [] + waited = checks_passed("tea", "1", "abc", {"CI / tests (pull_request)"}, tea(itertools.repeat('{"state": "pending", "total_count": 0, "statuses": []}')), slept.append) + self.assertIsInstance(waited, Failure) + self.assertIn("CI / tests (pull_request)", waited.reason) + self.assertEqual(sum(slept), WAIT_SECONDS) + + def test_fails_on_tea_where_a_check_failed(self): + self.assertIsInstance(checks_passed("tea", "1", "abc", set(), tea(['{"state": "failure", "total_count": 1}']), self.fail), Failure) + + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/larv_review/reviewer_header.py b/bin/larv_review/reviewer_header.py index c4f06fde..f9be7e64 100644 --- a/bin/larv_review/reviewer_header.py +++ b/bin/larv_review/reviewer_header.py @@ -5,12 +5,12 @@ import pathlib from git_cli.git_repo import branch_titles, git, top from review_rules.round_titles import cap, round_counts from failure import Failure -from chunk_preflight.choices import forge_of +from forge.commands import forge_of, runner from record_store.stores import goals_store, local_file, store from larv_review.history_commands import history_file, places_report from project_config.main import located, title_templates from review_rules.review_folder import made_review_folder -from deploy_release.forge import open_pull, runner +from forge.pulls import open_pull from larv_review.plan_listing import plan_listing from plan_store.stores import store as plan_store from review_rules.reviewer_context import principles_line, starts_bare From d6226070db59cd9dfef94fe994fa6adce75d4f7a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:44:02 +0100 Subject: [PATCH 04/16] =?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);=20the=20move?= =?UTF-8?q?=20adds=20no=20attack=20surface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From ac9566510ce1dae498633317847be1d7c48dc428 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:49:16 +0100 Subject: [PATCH 05/16] Test that a failing finish in a Jira plan says not finished --- bin/todo_item/test_todo_item.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index db35049b..57cb3b1e 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -296,6 +296,10 @@ class FinishInJira(TodoItem): self.assertIn("the issues' history is the changelog", err) self.assertEqual((list(self.plan.rows), self.changelog.read_text()), ([3], CHANGELOG)) + def test_a_failing_finish_says_not_finished(self): + self.plan.fails = "Jira refused" + self.assertEqual(self.run_main("finish", "3"), (1, "", "not finished: Jira refused\n")) + def test_doesnt_read_the_changelog(self): self.changelog.write_bytes(b"# Changelog\n\n\xff\n") self.assertEqual(self.run_main("finish", "3")[::2], (0, "")) From 9f4ccbe1113dae29c65707cf8e8770db9b409725 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:52:55 +0100 Subject: [PATCH 06/16] Pin the forge helpers' failure reasons and the give-up's read count in tests --- bin/forge/test_forge.py | 45 ++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/bin/forge/test_forge.py b/bin/forge/test_forge.py index 9b72aafe..b19a0dd0 100644 --- a/bin/forge/test_forge.py +++ b/bin/forge/test_forge.py @@ -6,8 +6,8 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from forge.pulls import checks_passed, POLL_SECONDS, required_checks, WAIT_SECONDS -from failure import Failure +from forge.pulls import checks_passed, open_pull, POLL_SECONDS, required_checks, WAIT_SECONDS +from forge.commands import forge_of, gitea from forge.commands import forge_of @@ -17,6 +17,23 @@ class ForgeOf(unittest.TestCase): self.assertEqual(forge_of("https://gitea.larvit.se/o/r.git"), "tea") +# An answer longer than the 200 characters a failure quotes of it, in a shape no call reads. +LONG = "[" + ", ".join(["1"] * 100) + "]" + + +class Gitea(unittest.TestCase): + def test_fails_with_giteas_message_where_it_answers_an_error(self): + self.assertEqual(gitea(lambda command: '{"message": "not found"}', "repos/o/r").reason, "tea api repos/o/r: not found") + + def test_fails_quoting_the_first_200_characters_where_tea_prints_no_json(self): + self.assertEqual(gitea(lambda command: "x" * 300, "repos/o/r").reason, f"tea api repos/o/r printed no JSON: {'x' * 200}") + + +class OpenPull(unittest.TestCase): + def test_fails_quoting_the_first_200_characters_where_tea_lists_pull_requests_in_another_shape(self): + self.assertEqual(open_pull("tea", "item-3", "abc", lambda command: LONG).reason, f"tea api listed pull requests in a shape that can't be read: {LONG[:200]}") + + def tea(statuses: typing.Iterable[str], branch: str = '{"name": "main"}') -> typing.Callable[[list[str]], str]: """A tea answering each read of the head's status with the next of statuses, and of branch main with branch.""" answers = iter(statuses) @@ -33,8 +50,8 @@ class RequiredChecks(unittest.TestCase): def test_reads_none_on_tea_where_the_protection_turns_status_checks_off(self): self.assertEqual(required_checks("tea", "main", tea([], '{"name": "main", "enable_status_check": false, "status_check_contexts": ["CI / tests (pull_request)"]}')), set()) - def test_fails_on_tea_where_the_branch_reads_in_another_shape(self): - self.assertIsInstance(required_checks("tea", "main", tea([], "[]")), Failure) + def test_fails_on_tea_quoting_the_first_200_characters_where_the_branch_reads_in_another_shape(self): + self.assertEqual(required_checks("tea", "main", tea([], LONG)).reason, f"tea api answered branch main in a shape that can't be read: {LONG[:200]}") def test_reads_none_on_github_whose_watch_covers_them(self): self.assertEqual(required_checks("gh", "main", self.fail), set()) @@ -59,15 +76,23 @@ class ChecksPassed(unittest.TestCase): passed = '{"state": "success", "total_count": 1, "statuses": [{"context": "CI / tests (pull_request)", "status": "success"}]}' self.assertIsNone(checks_passed("tea", "1", "abc", {"CI / *"}, tea([passed]), self.fail)) - def test_gives_up_on_tea_after_the_wait_naming_a_required_check_that_never_reported(self): - slept = [] - waited = checks_passed("tea", "1", "abc", {"CI / tests (pull_request)"}, tea(itertools.repeat('{"state": "pending", "total_count": 0, "statuses": []}')), slept.append) - self.assertIsInstance(waited, Failure) - self.assertIn("CI / tests (pull_request)", waited.reason) + def test_gives_up_on_tea_after_the_wait_naming_each_required_check_that_never_reported(self): + slept, read = [], [] + pending = tea(itertools.repeat('{"state": "pending", "total_count": 0, "statuses": []}')) + waited = checks_passed("tea", "1", "abc", {"lint", "CI / tests (pull_request)"}, lambda command: read.append(command) or pending(command), slept.append) + self.assertEqual(waited.reason, "gave up on pull request 1 after 30 minutes: CI / tests (pull_request), lint, which the protection requires, never passed") self.assertEqual(sum(slept), WAIT_SECONDS) + self.assertEqual(len(read), WAIT_SECONDS // POLL_SECONDS + 1) + + def test_gives_up_on_tea_after_the_wait_saying_a_check_is_still_pending(self): + waited = checks_passed("tea", "1", "abc", set(), tea(itertools.repeat('{"state": "pending", "total_count": 1, "statuses": []}')), lambda seconds: None) + self.assertEqual(waited.reason, "gave up on pull request 1 after 30 minutes: a check is still pending") def test_fails_on_tea_where_a_check_failed(self): - self.assertIsInstance(checks_passed("tea", "1", "abc", set(), tea(['{"state": "failure", "total_count": 1}']), self.fail), Failure) + self.assertEqual(checks_passed("tea", "1", "abc", set(), tea(['{"state": "failure", "total_count": 1}']), self.fail).reason, "a check on pull request 1 ended in failure") + + def test_fails_on_tea_quoting_the_first_200_characters_where_the_status_reads_in_another_shape(self): + self.assertEqual(checks_passed("tea", "1", "abc", set(), tea([LONG]), self.fail).reason, f"tea api printed no commit status for abc: {LONG[:200]}") From 1598b6178e2986a480733590db237c0f516fcf8e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:58:40 +0100 Subject: [PATCH 07/16] Indent the Jira finish call as its case's other bodies --- bin/todo_item/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index 3b0a8443..b4f780bc 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -117,7 +117,7 @@ def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.T done = reported(plan.edit(args.id, {"Release": args.release}, None), "not moved", lambda written: f"Moved item {written.id} to release {args.release} in {plan.label}.") case _: # A Jira plan keeps no changelog: the issues' history in Jira says what shipped. - done = finish(args, plan, None if config.epic else store(config, "changelog")) + done = finish(args, plan, None if config.epic else store(config, "changelog")) if isinstance(done, Failure): print(done.reason, file=sys.stderr) return 1 From 1c031866a42b7de9323f81f7063f9fe3b2d4c329 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 16 Nov 2026 23:58:50 +0100 Subject: [PATCH 08/16] =?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);=20the=20inden?= =?UTF-8?q?tation=20note=20was=20fixed=20as=20a=20style=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 2c504133b83df33c17d59b41f5f45a18e045ff37 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:01:09 +0100 Subject: [PATCH 09/16] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20the=20Jira?= =?UTF-8?q?=20sentence=20moves=20after=20the=20finish=20sentence,=20the=20?= =?UTF-8?q?help=20and=20error=20text=20name=20Jira,=20and=20the=20test=20n?= =?UTF-8?q?ames=20lose=20the=20negation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 2 +- README.md | 2 +- bin/chunk_pr/main.py | 3 ++- bin/todo_item/main.py | 6 ++++-- bin/todo_item/test_todo_item.py | 4 ++-- skills/larv-review/SKILL.md | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6832601f..0d15cac1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,7 +18,7 @@ How work proceeds in any repo, unless the repo's `AGENTS.md` says otherwise. The - **Ask, don't guess.** Three choices are always the human's: a goal; a release, meaning the items planned into it and when it is cut; and a change to loop-claude's routing ladder, its rungs included. Any other rule that asks the human's approval reserves that choice too. Ask about a reserved choice. For any other choice, first check whether the goals already answer it. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Otherwise take the option you would recommend, and record it with its reason: in the item's detail, or, where it governs later work, as the next sentence says. A recommendation you can give a reason for is not a guess. Ask only where you have no recommendation. Write every answer once, where it belongs, never only in chat: a goal in the goals file, a working rule in `AGENTS.md`, a standing choice in a comment at the one place it governs, or in `docs/decisions.md` once made in more than one place. When an answer holds a goal and a choice, write the goal in the goals file, and record as a choice only what the goal leaves open. - **Bench a syntax with the people who write it.** Before a new or changed spelling of something users read or write ships — markdown, HTML, a config key, a CLI flag — a panel of fresh-context readers, seated as those users from the goals file's `## Audience`, picks it. - **Implement the simplest change that solves the item, and ship it with `/larv-review`.** Whenever a test can check the change, write that test first and see it fail. Take its expected values from the item, never from the code. larv-review's reviewers hold the change to the technical principles, and a finding against one names it. Read a file in the principles folder the project's config sets (`~/.claude/bin/project-config principles` prints it) only when the item changes it, a finding or a record you write names it, or you decline a finding. -- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. A plan kept in Jira takes no bullet: the issues' history is its changelog, and `todo-item finish` there refuses `--changelog`. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish ` removes the item with its detail, and adds the bullet you pass with `--changelog `; it refuses while a decision cites the item. A chunk finishes its items as it merges, through `chunk-pr merge --finish `, which takes the same flags (`larv-review` §5). +- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish ` removes the item with its detail, and adds the bullet you pass with `--changelog `; it refuses while a decision cites the item. A plan kept in Jira takes no bullet, since the issues' history is its changelog: `finish` there refuses `--changelog`. A chunk finishes its items as it merges, through `chunk-pr merge --finish `, which takes the same flags (`larv-review` §5). - **Releases are the human's.** The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision. - **Open each plan item or ticket with a bold one-sentence tagline**, so the taglines alone say what a release holds. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and doesn't say anything about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: `**Accept undefined in MetadataValue and drop such keys on output.**` BANNED: `MetadataValue accepts undefined; such keys are dropped on output`. - **File a security finding the moment it is found.** A security finding — a leaked credential, secret or PII, an auth bypass, an injection — goes under the next release, marked `security`, naming the exposure and the path it reaches. `~/.claude/bin/rank_todo.py` ranks it first in its release, after only the open questions, which wait for me. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will unmark it if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius. diff --git a/README.md b/README.md index 3f65426f..a9b5d21e 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `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 on the project's routing ladder, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule. -- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show ` one item's row and detail; `add …` files an item under the next free ID, `edit …` sets an item's cells or detail, and `move --release ` sets an item's release; `finish ` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`, except for a plan kept in Jira, whose issues' history is its changelog. Each change ranks a markdown plan. `todo-item --help` states the flags. +- `todo-item` reads and changes a project's plan, whatever holds it: `list` prints the items in the plan's order and `show ` one item's row and detail; `add …` files an item under the next free ID, `edit …` sets an item's cells or detail, and `move --release ` sets an item's release; `finish ` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`, except for a plan kept in Jira. Each change ranks a markdown plan. `todo-item --help` states the flags. - `touch-predictions record ...` appends what a chunk's items were predicted to touch, under `Touches:` in their details, beside the files and parts its branch touched, to the record the config names as `touch-predictions`; `touch-predictions --help` shows the spelling and how a part is named. `chunk-preflight` reads the same predictions to name the items that may start chunks at once. - `wait-for [] [--timeout ]` waits until a file a background job writes holds a line matching the pattern, and prints it. diff --git a/bin/chunk_pr/main.py b/bin/chunk_pr/main.py index 93075e38..3515857b 100644 --- a/bin/chunk_pr/main.py +++ b/bin/chunk_pr/main.py @@ -30,7 +30,8 @@ merge merges the pull request in its turn: the chunks of one project on this 1. fetches origin and merges its default branch into the branch, as sync does; 2. finishes each plan item a --finish names with `todo-item finish`, passing on --changelog or --no-changelog (a Jira plan takes no --changelog, as todo-item says), - and commits what that changed in the plan and the changelog, so both change only at merge time, on top of every chunk merged before; + and commits what that changed in the plan and the changelog, so both change only + at merge time, on top of every chunk merged before; 3. pushes, also where step 2 failed after step 1 brought changes in; 4. waits for the pull request's checks, and those origin's default branch requires, to pass on the head; where no check reports within a minute, it takes the pull request diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index b4f780bc..096d89f0 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -63,7 +63,9 @@ mistake. It prints `Finished item in .` It doesn't write anything whi finish --no-changelog also drops an item no chunk built. In a Jira epic, finish doesn't remove anything: it moves the item's issue by the transition, and to the status, that the config's `jira-finish-transition` and `jira-finish-status` name, as -`project-config --help` shows. It needs neither --changelog nor --no-changelog (it accepts --no-changelog), never reads the changelog, and refuses --changelog, since the issues' history is the changelog. docs/decisions.md isn't checked. +`project-config --help` shows. The issues' history is the changelog, so finish there needs +neither --changelog nor --no-changelog, and never reads the changelog. It refuses --changelog and +accepts --no-changelog. docs/decisions.md isn't checked. It fails, moving no issue, where the config sets neither, where the issue has no such transition from its present status, or where the transition leads to another status or to one Jira doesn't count as done. An issue that no chunk built is dropped in Jira, not with finish, which would mark it done. @@ -222,7 +224,7 @@ def finish(args: argparse.Namespace, plan: PlanStore, changelog: RecordStore | N """Finish item args.id in plan. changelog is where its bullet goes, or None where the plan keeps no changelog.""" if changelog is None: if args.changelog is not None: - return Failure("not finished: this plan keeps no changelog, since the issues' history is the changelog; drop --changelog") + return Failure("not finished: the plan is a Jira epic, so the issues' history is the changelog; drop --changelog") return reported(plan.finish(args.id), "not finished", lambda written: f"Finished item {written.id} in {plan.label}.") held = changelog.held() if isinstance(held, Failure): diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index 57cb3b1e..dc021dec 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -278,7 +278,7 @@ class FinishInJira(TodoItem): patched.start() self.addCleanup(patched.stop) - def test_finishes_without_either_flag_and_leaves_a_changelog_that_exists_alone(self): + def test_finishes_without_either_flag_and_doesnt_touch_the_changelog(self): self.changelog.write_text(CHANGELOG) self.assertEqual(self.run_main("finish", "3"), (0, "Finished item 3 in the plan in memory.\n", "")) self.assertEqual((self.plan.rows, self.changelog.read_text()), ({}, CHANGELOG)) @@ -288,7 +288,7 @@ class FinishInJira(TodoItem): self.assertEqual(self.run_main("finish", "3", "--no-changelog"), (0, "Finished item 3 in the plan in memory.\n", "")) self.assertEqual(self.changelog.read_text(), CHANGELOG) - def test_refuses_a_bullet_writing_nothing_and_says_the_issues_history_is_the_changelog(self): + def test_refuses_a_bullet_and_says_the_issues_history_is_the_changelog(self): self.changelog.write_text(CHANGELOG) code, out, err = self.run_main("finish", "3", "--changelog", "Runs are fast.") self.assertEqual((code, out), (1, "")) diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 023bb8bf..84d57d40 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -202,7 +202,7 @@ Launch prose-reviewer with what the diff touched and every section this review c 1. Read the finished PR against the goals file's goals and code health, unless that file 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. When `origin/` moves after that, return to §4, and keep the scoring run already recorded. Where the chunk recorded a paired ruling, run it again at the new head and record it: it read the head before the other chunk's merge came in. 3. Run `~/.claude/bin/touch-predictions record ...` in the worktree, naming the chunk's items: it records what they were predicted to touch beside what the branch touched, where the project's config names that record. A later pass through this step, after a return to §4, skips it. Commit and push it; the commit re-enters no pass. Leave the chunk's items in the plan, and write no changelog bullet in the branch: step 4 does both, so that `todo.md` and `CHANGELOG.md` never conflict between chunks. Revise any decision that cites an item now, since `todo-item finish` refuses while one does. -4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. Give it one `--finish ` per item the chunk ships, each with the arguments `todo-item finish` takes (`todo-item --help`), as in `chunk-pr merge --finish 12 --changelog '' --finish 13 --no-changelog`. Where the plan is a Jira epic, give no `--changelog`: the issues' history is the changelog, and `todo-item finish` there refuses a bullet. The project's chunks merge one at a time. In its turn, `chunk-pr merge` merges `origin/` into the branch, finishes those items, pushes, and waits for the pull request's checks to pass; then it takes the first merge method the repository allows on its forge. Where it stops, do what it asks and run it again with the same arguments: +4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. Give it one `--finish ` per item the chunk ships, each with the arguments `todo-item finish` takes (`todo-item --help`), as in `chunk-pr merge --finish 12 --changelog '' --finish 13 --no-changelog`. Where the plan is a Jira epic, give no `--changelog`. The project's chunks merge one at a time. In its turn, `chunk-pr merge` merges `origin/` into the branch, finishes those items, pushes, and waits for the pull request's checks to pass; then it takes the first merge method the repository allows on its forge. Where it stops, do what it asks and run it again with the same arguments: - **A merge conflict.** Resolve it, commit and push. Rerun only the passes whose triggers the resolution's own lines meet (§3), each in a round of its own. - **A paired ruling to run again.** `chunk-pr merge` has merged the default branch in and pushed. Run the ruling at that head, record it, commit and push. Don't return to §4 for it: the next turn waits for the checks at the new head. - **An owed scoring run, or a queue another pull request holds.** Record the run, or wait, as the message says. From 315b4da925bb70d17d37c03bd65ebab7fc760f51 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:01:09 +0100 Subject: [PATCH 10/16] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20Other?= =?UTF-8?q?wise=20nit=20and=20the=20preflight=20count=20are=20answered=20i?= =?UTF-8?q?n=20the=20summary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 8c17462321ebdfa9359273d3b675d3d8b8cc794c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:01:09 +0100 Subject: [PATCH 11/16] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20er?= =?UTF-8?q?ror=20text=20now=20names=20Jira?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From e4529bee9c6a94131700e8347094bacf0c45323e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:02:47 +0100 Subject: [PATCH 12/16] Finish item 394 in the plan --- CHANGELOG.md | 4 ++++ todo.md | 22 ---------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f202ca27..a8ce077e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- A plan kept as a Jira epic takes no changelog bullet: `todo-item finish` there needs neither `--changelog` nor `--no-changelog`, and refuses `--changelog`, since the issues' history is the changelog. + ## 0.11.0 - `adf_codec.convert` can now convert ADF to markdown and back without losing a block's `localId` or the empty paragraphs Jira uses for spacing, so a Jira or Confluence document read and saved back unedited comes back identical: `markdown_to_adf_lossless`, `adf_to_markdown_lossless` and `adfs_to_markdown_lossless`. No tool calls them yet. diff --git a/todo.md b/todo.md index a9eeb980..af83bae4 100644 --- a/todo.md +++ b/todo.md @@ -20,7 +20,6 @@ | 338 | 0.12.0 | | owner | **Script each step that 0.9.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 2.3 | | 288 | 0.12.0 | | | **Point the two reading-cost decisions at code health and goal 1.4's counter-signal, in place of the goal 1.1 they cite.** | 1 | 2 | 1 | 2 | 1 | code health by 1, 1.4 by 1 | 2.2 | | 391 | 0.12.0 | | | **Read and write a Jira epic issue's description and a Confluence record page through the lossless pair, so saving an unedited document leaves it unchanged.** | 3 | 2 | 3 | 6 | 5 | 1.6 by 6, 1.1 by 3 | 1.9 | -| 394 | 0.12.0 | | | **Write no changelog bullet for a plan kept in Jira: `todo-item finish` there needs neither --changelog nor --no-changelog and refuses --changelog, since the issues' history is the changelog.** | 2 | 2 | 3 | 5 | 3 | 1.6 by 4 | 1.3 | | 319 | 0.12.0 | | | **Start a fresh session with a brief of the chunk when a rung step changes the worker's model, in place of resuming the old session.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 2, 1.4 by 2 | 1.2 | | 309 | 0.12.0 | | | **Run a scoring run's second pass on one head with two seats in place of four, once `larv-review agreement` shows the seats agree with each other more than a run agrees with its rerun.** | 2 | 2 | 2 | 4 | 2 | 1.4 by 3 | 1.2 | | 299 | 0.12.0 | | | **Replay the archived judge verdicts through code rules and a classifier trained locally on the archive, and file an item for each verdict kind one of them decides with no missed interrupt.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 1.0 | @@ -196,27 +195,6 @@ Both `docs/decisions.md` entries under `reading cost: a rise is …` and `readin Open before building: the lossless markdown is less readable than the portable one (upstream larvit/adf-codec#185), and agents and the judge read the plan's details from it. Decide how a detail stays readable, for example by reading lossless and showing a person a portable view. Test that an unedited issue and page save back identical. The item ships alone because its R is above 5. -### 394. Write no changelog bullet for a plan kept in Jira: `todo-item finish` there needs neither --changelog nor --no-changelog and refuses --changelog, since the issues' history is the changelog. - -The human ruled on 2026-11-16 that a project whose plan is a Jira epic keeps no changelog of its own: the issues' history in Jira already says what shipped. Today `todo-item finish` asks for `--changelog ` or `--no-changelog` whenever the configured changelog holds text, for a Jira plan too, and writes the bullet to `CHANGELOG.md` or the Confluence page. - -Done when, for a plan kept in Jira: - -- `todo-item finish ` moves the issue without asking for either flag, and doesn't read or write the changelog; -- `todo-item finish --changelog ` refuses, writing nothing, and says the issues' history is the changelog; -- `--no-changelog` is still accepted, so `chunk-pr merge --finish --no-changelog` keeps working; -- `CLAUDE.md` → "Working loop" and larv-review §5 say a Jira plan takes no changelog bullet. - -A plan kept as todo.md behaves as today. A client's own `CHANGELOG.md` stays the team's: the loop just stops adding to it. - -Touches: - -- `bin/todo_item/main.py`: `finish`, `(module)` (small) -- `bin/todo_item/test_todo_item.py` -- `bin/chunk_pr/main.py`: `(module)` (small) -- `CLAUDE.md`: `## Working loop` (small) -- `skills/larv-review/SKILL.md`: `## 5. Goal alignment, then merge` (small) - ### 319. Start a fresh session with a brief of the chunk when a rung step changes the worker's model, in place of resuming the old session. On SWE-bench Verified with Haiku 4.5 and Opus 4.7, handing the strong model the weak model's transcript solved 69.2% at $1.61 a task; starting the strong model fresh solved 79.2% at $0.90 (arXiv 2608.24358, The Handoff Tax). A model switch also rereads the whole context uncached (Claude Code prompt caching docs). A worker that steps from Sonnet 5.5 to Opus 5.5 by `--resume` is the raw handoff; an effort-only step within one model keeps the cache and isn't. The escalated subagent, which starts fresh with the trigger's evidence, already follows the pattern that won. From 92ffec794968f07fb0d48b726d28badc8b1cb1ed Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:10:10 +0100 Subject: [PATCH 13/16] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20the=20docst?= =?UTF-8?q?rings=20claim=20head-pinning=20only=20where=20a=20call=20takes?= =?UTF-8?q?=20head,=20and=20the=20wait=20comments=20name=20the=20forge=20e?= =?UTF-8?q?ach=20covers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- bin/deploy_release/release_pull.py | 4 ++-- bin/forge/__init__.py | 1 - bin/forge/commands.py | 4 ++-- bin/forge/pulls.py | 9 +++------ bin/forge/test_forge.py | 3 +-- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 67188db2..f9ca321c 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `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. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. - `deploy_release` imports `release_plan`'s `release_standing`. -- `forge/` tells a GitHub origin from a Gitea one and runs its CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review`. +- `forge/` tells a GitHub origin from a Gitea one and runs that forge's CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review`. - `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, verdicts, premises and records. - `loop_claude` runs `chunk-preflight` as a process of its own. diff --git a/bin/deploy_release/release_pull.py b/bin/deploy_release/release_pull.py index fa2ae8ef..5d919e01 100644 --- a/bin/deploy_release/release_pull.py +++ b/bin/deploy_release/release_pull.py @@ -1,6 +1,6 @@ -"""The pull request steps of a cut. They run gh where origin is on GitHub and tea elsewhere, as `forge.commands` tells the two apart. +"""Opening and merging a cut's pull request, with gh where origin is on GitHub and with tea elsewhere. -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. +merge is pinned to head, the commit origin's release branch points at: the forge merges the pull request only while its head is still that commit, so a push to the branch after its checks passed is never merged. """ from failure import Failure from forge.commands import Forge, gitea, Run diff --git a/bin/forge/__init__.py b/bin/forge/__init__.py index 46a2dc1a..e69de29b 100644 --- a/bin/forge/__init__.py +++ b/bin/forge/__init__.py @@ -1 +0,0 @@ -"""The forge a checkout's origin is on, GitHub or Gitea, and the calls to it that several tools make: `commands.py` tells the two apart and runs their CLIs, `pulls.py` finds a pull request and waits for its checks.""" diff --git a/bin/forge/commands.py b/bin/forge/commands.py index c74168f4..576c5aad 100644 --- a/bin/forge/commands.py +++ b/bin/forge/commands.py @@ -5,10 +5,10 @@ import typing from failure import Failure -# The CLI that talks to a forge: gh for a github.com origin, tea for any other. +# The CLI of the forge that origin is on, as forge_of picks it. Forge = typing.Literal["gh", "tea"] -# Runs a command in the clone: what it printed, or a Failure with its reason. +# Runs a command in the checkout: what it printed, or a Failure with its reason. Run = typing.Callable[[list[str]], str | Failure] diff --git a/bin/forge/pulls.py b/bin/forge/pulls.py index 639b2336..5644a66f 100644 --- a/bin/forge/pulls.py +++ b/bin/forge/pulls.py @@ -1,7 +1,4 @@ -"""Finding a pull request from origin's own branch, and waiting for its checks. - -Each call is pinned to head, a commit on that branch: it takes only a pull request from origin itself whose head is that commit. So a fork's pull request from a branch of the same name is never taken. -""" +"""Finding a pull request from origin's own branch, and waiting for the checks on its head commit.""" import fnmatch import time import typing @@ -9,9 +6,9 @@ import typing from failure import Failure from forge.commands import Forge, gitea, Run -# How long checks_passed waits between two reads of the head commit's status on Gitea. +# How long checks_passed waits between two reads: of the head commit's status on Gitea, or of gh's watch while it reports no checks. POLL_SECONDS = 10 -# How long checks_passed waits for the checks before it gives up; CI took about 3 minutes in 2026-11. +# How long checks_passed waits on Gitea for the checks before it gives up; CI took about 3 minutes in 2026-11. gh's watch waits as long as the checks run. WAIT_SECONDS = 30 * 60 diff --git a/bin/forge/test_forge.py b/bin/forge/test_forge.py index b19a0dd0..ee0675a4 100644 --- a/bin/forge/test_forge.py +++ b/bin/forge/test_forge.py @@ -8,7 +8,6 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from forge.pulls import checks_passed, open_pull, POLL_SECONDS, required_checks, WAIT_SECONDS from forge.commands import forge_of, gitea -from forge.commands import forge_of class ForgeOf(unittest.TestCase): @@ -17,7 +16,7 @@ class ForgeOf(unittest.TestCase): self.assertEqual(forge_of("https://gitea.larvit.se/o/r.git"), "tea") -# An answer longer than the 200 characters a failure quotes of it, in a shape no call reads. +# An answer no call can read, longer than the 200 characters of it that a failure quotes. LONG = "[" + ", ".join(["1"] * 100) + "]" From fe7e05da5a7a77edc2261e4242c5a98592d93617 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:10:10 +0100 Subject: [PATCH 14/16] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20dupli?= =?UTF-8?q?cate=20import=20and=20the=20head-pinning=20claims=20went=20with?= =?UTF-8?q?=20the=20prose=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From d0dd62c998629e60e801ea9f63256cbd20119778 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:10:10 +0100 Subject: [PATCH 15/16] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20RE?= =?UTF-8?q?ADME's=20package=20list=20matches=20the=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 27a4f838e5028f46b2f5ff1afe3ba62e314a69f0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 00:11:53 +0100 Subject: [PATCH 16/16] Finish item 287 in the plan --- todo.md | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/todo.md b/todo.md index af83bae4..1f887683 100644 --- a/todo.md +++ b/todo.md @@ -15,7 +15,6 @@ | 303 | 0.12.0 | | defect | **Archive each judge run's prompt and json reply beside the verdict it gave, so judge cost, replays and backups cover the judge as they cover the worker.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3, 3 by 2 | 4.2 | | 306 | 0.12.0 | | | **Set a strategy that keeps loop-claude's archive and larv-review's review folders backed up and small over the years, compressing older entries without losing any.** | 3 | 2 | 4 | 7 | 5 | 3 by 5 | 3.9 | | 304 | 0.12.0 | 303 | defect | **Archive each review-replay and judge-replay run's transcript beside its result, so a replay that decided a rung can be checked and re-priced later.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 2, 3 by 2 | 3.8 | -| 287 | 0.12.0 | | | **Move the forge helpers `Forge`, `forge_of`, `runner`, `open_pull`, `merged_pull`, `pull_at`, `gitea`, `checks_passed` and `required_checks` into one module that `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review` all import from, so no tool imports another tool's internals for them.** | 3 | 1 | 3 | 5 | 5 | code health by 3 | 2.9 | | 387 | 0.12.0 | | | **Bind a project's rung to its ladder in one value, so the routing functions and `Cycle` take one argument for both.** | 3 | 1 | 3 | 5 | 5 | code health by 3 | 2.9 | | 338 | 0.12.0 | | owner | **Script each step that 0.9.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 2.3 | | 288 | 0.12.0 | | | **Point the two reading-cost decisions at code health and goal 1.4's counter-signal, in place of the goal 1.1 they cite.** | 1 | 2 | 1 | 2 | 1 | code health by 1, 1.4 by 1 | 2.2 | @@ -133,29 +132,6 @@ Touches: - `bin/judge_replay/test_judge_replay.py` - `bin/loop_claude/cycle/judge.py`: `judge_args`, `run_judge` (small) -### 287. Move the forge helpers `Forge`, `forge_of`, `runner`, `open_pull`, `merged_pull`, `pull_at`, `gitea`, `checks_passed` and `required_checks` into one module that `chunk_preflight`, `chunk_pr`, `deploy_release` and `larv_review` all import from, so no tool imports another tool's internals for them. - -Today the helpers live in two tools. `Forge` is defined in `bin/chunk_preflight/gathered.py` and imported by `bin/chunk_preflight/choices.py`, `bin/chunk_preflight/facts.py`, `bin/chunk_preflight/main.py` and `bin/chunk_pr/main.py`, and again through `choices` by `bin/deploy_release/forge.py`. `forge_of` lives in `choices.py`, which `bin/chunk_pr/main.py`, `bin/deploy_release/cut.py` and `bin/larv_review/reviewer_header.py` import. `open_pull`, `runner` and `gitea` live in `bin/deploy_release/forge.py`, which `bin/chunk_pr/main.py` and `bin/larv_review/reviewer_header.py` import. So `deploy_release` imports `chunk_preflight`, and `chunk_pr` and `larv_review` import both. - -Both comprehension seats of PR #453's paired ruling (2026-11-09) named this web as a place that cost them time, and neither saw a reason for it: a second forge would need edits in `chunk_preflight`, `deploy_release`, `chunk_pr` and `larv_review`. - -Put the seven helpers in a folder named by what it holds, such as `bin/forge/`, and import them from there. Keep each helper's behaviour and its tests. `chunk_preflight/choices.py` keeps `pulls_command`, which is preflight's own. Check `docs/decisions.md` for a mention of where a helper lives, and update it. - -Touches: - -- `bin/deploy_release/forge.py` -- `bin/chunk_preflight/gathered.py`: `Forge` -- `bin/chunk_preflight/choices.py`: `forge_of`, `(module)` (small) -- `bin/chunk_preflight/facts.py`: `(module)` (small) -- `bin/chunk_preflight/main.py`: `(module)` (small) -- `bin/chunk_pr/main.py`: `(module)` (small) -- `bin/chunk_pr/approval.py`: `(module)` (small) -- `bin/deploy_release/cut.py`: `(module)` (small) -- `bin/larv_review/reviewer_header.py`: `(module)` (small) -- `bin/chunk_pr/test_chunk_pr.py` -- `bin/chunk_preflight/test_chunk_preflight.py` -- `bin/deploy_release/test_deploy_release.py` - ### 387. Bind a project's rung to its ladder in one value, so the routing functions and `Cycle` take one argument for both. Filed by PR #553, which made the routing ladder a file a project may replace. Its stability round 1 found two places the comprehension seats name as hard, touched and no easier to read: `bin/loop_claude/routing.py` `unfinished_route` took `ladder` as a fourth parameter, and `Cycle` in `bin/loop_claude/cycle/run.py` gained the field `ladder`. The patch threaded the ladder as an argument, since a wider change did not fit a patch cut during an outage.