diff --git a/README.md b/README.md index 145b579f..15d6349d 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `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`. - `do_epic/` holds `do-epic`, the tool that drives one Jira epic: - - `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `epic_run.py` holds what one run of do-epic keeps, and starts the chunks that may start now. + - `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `epic_run.py` holds what stays the same through one run of do-epic, such as its config, its Jira store and its paths, and starts the chunks that may start now. - `planning.py` settles, before the chunks start, where each open issue is worked, its scores and the order the issues start in, through `split.py`, `repo_pick.py`, `issue_scores.py` and `ranking.py`. - `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. - `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `parking.py` parks such a chunk after a cycle and polls the gate until its worker has something to do. diff --git a/bin/claude_code/entries.py b/bin/claude_code/entries.py index 43d21637..1d5aced4 100644 --- a/bin/claude_code/entries.py +++ b/bin/claude_code/entries.py @@ -86,7 +86,7 @@ def parse_entry(raw: str | bytes) -> Entry | None: def json_objects(raw: bytes) -> list[dict]: """The lines of a transcript or a stream-json stream that are JSON objects, parsed.""" - return [found for line in raw.splitlines() if (found := json_object(line))] + return [found for line in raw.splitlines() if (found := json_object(line)) is not None] def entries_of(raw: bytes) -> list[Entry]: diff --git a/bin/claude_code/test_claude_code.py b/bin/claude_code/test_claude_code.py index 186b6b47..7ce0780e 100644 --- a/bin/claude_code/test_claude_code.py +++ b/bin/claude_code/test_claude_code.py @@ -100,8 +100,8 @@ class Parse(unittest.TestCase): self.assertIsNone(entries.parse_entry("[1, 2]")) def test_a_stream_parses_into_an_entry_per_line_that_is_a_json_object(self): - raw = b'{"type": "user", "message": {"content": "do it"}}\nnot json\n\n{"type": "summary"}\n' - self.assertEqual(entries.entries_of(raw), [entries.HumanTurn(text="do it"), entries.Entry()]) + raw = b'{"type": "user", "message": {"content": "do it"}}\nnot json\n\n{"type": "summary"}\n{}\n' + self.assertEqual(entries.entries_of(raw), [entries.HumanTurn(text="do it"), entries.Entry(), entries.Entry()]) self.assertEqual(entries.entries_of(b""), []) diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 52fd6900..d0e33725 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -353,7 +353,7 @@ class Landed(enum.Enum): class How(enum.Enum): - """How a finished chunk's issue moves, where it moves to no status the config names.""" + """How a finished chunk's issue moves when it doesn't move to a status the config names.""" # do-epic neither moves nor awaits it. LEFT = enum.auto() # Nobody would move it, so the loop stops. @@ -366,7 +366,7 @@ class How(enum.Enum): @dataclasses.dataclass(frozen=True) class ToStatus: - """do-epic moves a finished chunk's issue to status, trying a failed move again by way of through, None where there is none.""" + """do-epic moves a finished chunk's issue to status. Where that move fails, it moves the issue to through first and tries again; through is None where the config names no open status.""" status: str through: str | None @@ -376,7 +376,7 @@ Move = How | ToStatus def issue_move(landed: Landed, automated: bool, merged: str | None, opened: str | None, finishing: bool) -> Move: - """The move of the issue of a finished chunk whose work landed as landed says. automated says the team's automation moves issues, merged and opened are the statuses `jira-pull-request-merged-status` and `jira-pull-request-open-status` name, each None where the config names none, and finishing says the chunk is the epic's finishing. The first row that fits: + """The move of a finished chunk's issue. landed says where the chunk's work landed, automated says the team's automation moves issues, merged and opened are the statuses `jira-pull-request-merged-status` and `jira-pull-request-open-status` name, each None where the config names none, and finishing says the chunk is the epic's finishing. The first row that fits: | The chunk | The automation moves issues | A merged status is named | Move | |---|---|---|---| @@ -400,7 +400,7 @@ def issue_move(landed: Landed, automated: bool, merged: str | None, opened: str def handed_on(key: str, epic: EpicRun, landed: Landed = Landed.NOWHERE) -> Stop: - """The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done (the epic's finishing has none), and its parent too where the parent's sub-tasks now let it move (`parents_settled`), so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Where the team's automation moves issues, others move two kinds of issue. The automation moves the issue of a chunk whose work landed on the default branch, from its pull request: the stop waits for that move (`moved_by_automation`). The human moves their own task: the stop doesn't move or await anything. A chunk without a repo has no pull request, so its issue moves to done as ever, and so does a split item, once Jira counts each of its sub-tasks done. The automation doesn't see a pull request that merged into an epic's working branch: the stop moves that chunk's issue to the status `jira-pull-request-merged-status` names. Where none is named, it moves the issue to done, or stops where the automation moves issues, since then nobody would move it. do-epic's window closes as it exits.""" + """The stop of a do-epic whose chunk finished. It first moves the chunk's issue as `issue_move` says, and the issue's parent too where the parent's sub-tasks now let it move (`parents_settled`), so that no finished chunk starts again and what they block may start. Then it starts each chunk that may start now. Where the team's automation moves the issue, the stop waits for that move (`moved_by_automation`). do-epic's window closes as it exits.""" move = issue_move(landed, epic.config.automation_moves, epic.config.pull_merged_status, epic.config.pull_open_status, finishing=key == epic.key) issues: list[EpicIssue] | Failure match move: diff --git a/bin/do_epic/parking.py b/bin/do_epic/parking.py index ec7eef0b..d24d529c 100644 --- a/bin/do_epic/parking.py +++ b/bin/do_epic/parking.py @@ -18,7 +18,7 @@ DRIVER_PARKED = f"{chunk_prompt.DRIVER} parked the chunk while" def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finished: bool, based: str | None) -> str | Stop: """Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. told is the news its last cycle's worker got, None where the window just started, and finished says the judge ruled the chunk finished. based is the epic's working branch that `epic_based` recorded as the chunk's base when the window started, None where it recorded none. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh. - Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can, and a pull request no longer open, in a worktree that still stands, is news the worker hasn't been told: the worker removes the worktree. A pull request that doesn't merge into its base is news after every cycle that leaves it so: the worker levels the branch. + Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. For such a finished chunk, a gate that cannot be read is read again until it can (`Poll.first_gate`), and what the worker must still do is news (`news_after`). A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again. """ @@ -54,7 +54,11 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis def news_after(entered: gates.Open | Failure | None, finished: bool, by_human: bool, told: str | None) -> str: - """What to tell the worker of a chunk that isn't parked as its cycle ends, empty where there isn't anything. entered is what was read instead of a gate, None where the window just started. Only a chunk the judge ruled finished, whose pull request a person merges, has news: that its pull request doesn't merge into its base, after every cycle that leaves it so, or that its worktree stands though no pull request is open, unless told, the news its last worker got, says so already.""" + """What to tell the worker of a chunk that isn't parked as its cycle ends, empty where there isn't anything. entered is what was read instead of a gate, None where the window just started, and told is the news the last worker got. + + Only a chunk the judge ruled finished, whose pull request a person merges, has news, of one of two kinds: + - its pull request doesn't merge into its base: news after every cycle that leaves it so, and the worker levels the branch; + - its worktree stands though no pull request is open: news once, unless told says so already, and the worker removes the worktree.""" if not (finished and by_human): return "" if isinstance(entered, gates.Unmergeable): diff --git a/bin/do_epic/test_parking.py b/bin/do_epic/test_parking.py index 4a7d2154..53e58bce 100644 --- a/bin/do_epic/test_parking.py +++ b/bin/do_epic/test_parking.py @@ -19,12 +19,12 @@ class TheNewsOfAChunkThatIsNotParked(unittest.TestCase): def test_a_window_that_just_started_has_no_news(self) -> None: self.assertEqual(news_after(None, finished=True, by_human=True, told=None), "") - def test_a_gate_that_cannot_be_read_or_a_pull_request_with_news_of_its_own_adds_none(self) -> None: + def test_a_gate_that_cannot_be_read_or_one_that_lets_the_chunk_go_on_does_not_add_any_news(self) -> None: for entered in (Failure("no network"), Open("a reviewer requested changes")): with self.subTest(entered): self.assertEqual(news_after(entered, finished=True, by_human=True, told=""), "") - def test_an_unfinished_chunk_or_one_no_person_merges_has_no_news(self) -> None: + def test_an_unfinished_chunk_or_one_that_merges_without_a_person_has_no_news(self) -> None: for entered in (UNOPENED, UNMERGEABLE): for finished, by_human in ((False, True), (True, False), (False, False)): with self.subTest(entered=entered, finished=finished, by_human=by_human): diff --git a/bin/larv_review/reviewer_header.py b/bin/larv_review/reviewer_header.py index 872ca8cb..d80b2239 100644 --- a/bin/larv_review/reviewer_header.py +++ b/bin/larv_review/reviewer_header.py @@ -81,7 +81,7 @@ def unanswered_round(titles: list[str], pass_: str) -> int | Failure: def branch_summaries(default: str, home: pathlib.Path) -> list[str] | Failure: - """The branch's commit titles since default, each read as its summary in the project's title templates, so round titles count under any template. rule-hook's round-cap reads them its own way: guarded, and counting none where git fails.""" + """The branch's commit titles since default, each read as its summary in the project's title templates, so round titles count under any template. rule-hook's round-cap reads them its own way: guarded, and counting zero rounds where git fails.""" titles = branch_titles(default) if isinstance(titles, Failure): return titles diff --git a/bin/larv_review/scoring_due.py b/bin/larv_review/scoring_due.py index 2d7a17f7..b5d75b73 100644 --- a/bin/larv_review/scoring_due.py +++ b/bin/larv_review/scoring_due.py @@ -1,4 +1,4 @@ -"""When the plan calls a scoring run: a chunk that ships a floor item, one that empties a release work has landed towards, or one after a release cut unmeasured; and each reason it gives.""" +"""When the plan calls a scoring run: a chunk that ships a floor item, one that empties a release that work has already landed towards, or one after a release cut unmeasured; and each reason it gives.""" import pathlib diff --git a/bin/task_bench/figures.py b/bin/task_bench/figures.py index 2988c56d..f57d5c69 100644 --- a/bin/task_bench/figures.py +++ b/bin/task_bench/figures.py @@ -30,7 +30,7 @@ class Figures: class Result(typing.NamedTuple): """One run of a task at a side. figures is None where its claude ended without a result, as when it ran out of time. entries - holds what its stream tells, for the digest.""" + holds the entries of its stream, which the digest quotes.""" task: int side: Side @@ -63,7 +63,7 @@ HEADINGS = ["Bug", "Side", "Passed", *(column.heading for column in COLUMNS)] def figures(events: list[dict], bug_file: str) -> Figures | None | Failure: - """The figures of the run whose claude printed events, its stream's JSON lines, with bug_file the bug's file as the run's + """The figures of the run whose claude printed events, the objects parsed from its stream's lines, with bug_file the bug's file as the run's container names it. None where the stream holds no result. A Failure where the API refused the run, as on a token it doesn't take: such a run diff --git a/bin/task_bench/main.py b/bin/task_bench/main.py index 14a01955..2d501de6 100644 --- a/bin/task_bench/main.py +++ b/bin/task_bench/main.py @@ -61,7 +61,7 @@ Each bench empties its own folder first, and removes the folder every earlier be not, unless a bench or a gather is using it. So gather a bench before the next one starts. Exit 1, saying why, on an unknown or repeated argument, a missing --image or --test, a --seed, --bugs or --runs that is no whole -number from 1, or no token; and where git, docker or Gremlins fails, the seats' places name no Go file, the tests fail at a side +number from 1, or no token; and where git, docker or Gremlins fails, the seats' places don't name any Go file, the tests fail at a side without a bug, or no mutant becomes a bug. Where the API refuses a run, the bench stops there and exits 1 too, after the table of the runs that finished. gather exits 1, saying why, outside a checkout, without a digest, where loop-claude has saved no model for the project or the @@ -237,7 +237,7 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st trees[side] = tree files = [path for path in place_files(places) if pathlib.Path(trees["base"], path).is_file()] if not files: - return Failure("The places the seats found hard name no Go file that the base holds, so there is nowhere to plant a bug.") + return Failure("The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.") run = functools.partial(run_tool, prefix=given.get("--prefix"), env=env, killpg=os.killpg) mutants = killed_mutants(trees["base"], files, run, CPUS_PER_SLOT) if isinstance(mutants, Failure): @@ -274,10 +274,10 @@ def archived(commit: str, into: pathlib.Path, checkout: str, git: Git) -> str | try: with tarfile.open(archive) as held: held.extractall(into, filter="tar") - archive.unlink() except (tarfile.TarError, OSError) as failure: return Failure(f"could not unpack the tree at {commit}: {failure}") - return str(into) + removed = on_disk(f"remove {archive}", archive.unlink) + return removed if isinstance(removed, Failure) else str(into) def benched(bench: Bench, mutants: list[Mutant]) -> list[str] | Failure: @@ -300,7 +300,7 @@ def benched(bench: Bench, mutants: list[Mutant]) -> list[str] | Failure: def baseline_failure(bench: Bench) -> Failure | None: - """Why a side's tests don't pass without a planted bug; None where both sides' pass.""" + """Why a side's tests don't pass without a planted bug; None where they pass at both sides.""" for side, tree in bench.trees.items(): ran = tests_in_copy(bench.containers, tree, bench.folder) if isinstance(ran, Failure) or ran.code: @@ -336,7 +336,7 @@ def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes: def kept(bench: Bench, tasks: list[Task], names: dict[int, str], results: list[Result]) -> Failure | None: - """Writes results.json and the digest into the bench's folder, with names the bugs' names by number.""" + """Writes results.json and the digest into the bench's folder. names holds each bug's name by its number.""" in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in bench.trees.values()) recorded_runs = json.dumps({"sides": bench.sides, "seed": bench.asked.seed, "bugs": names, "runs": [recorded(result) for result in results]}, indent="\t") + "\n" digest_text = digest(bench.sides, table(results, names), [digested(task, results, bench.folder) for task in tasks], in_a_tree) diff --git a/bin/task_bench/plant.py b/bin/task_bench/plant.py index ebd2ba24..7f650369 100644 --- a/bin/task_bench/plant.py +++ b/bin/task_bench/plant.py @@ -88,8 +88,10 @@ def mutated(source: bytes, mutant: Mutant) -> bytes | None: def bug_at_sides(mutant: Mutant, diff: str, sources: dict[Side, bytes | None]) -> dict[Side, bytes] | None: - """The file of mutant with the bug in it, at the base and at the head, from the file at each side, None where the side has - none, and the diff of it from base to head. None where the mutant doesn't become a bug at one side or the other. + """The file of mutant with the bug in it, at the base and at the head. None where the mutant doesn't become a bug at one side + or the other. + + sources holds the file at each side, None where the side lacks it; diff is the file's diff from base to head. The bug is the same change to the same line at both sides, so only the code around it differs between them.""" at_head = line_at_head(diff, mutant.line) diff --git a/bin/task_bench/test_plant.py b/bin/task_bench/test_plant.py index e6316ca1..4f60a573 100644 --- a/bin/task_bench/test_plant.py +++ b/bin/task_bench/test_plant.py @@ -170,7 +170,7 @@ class BugAtSidesTest(unittest.TestCase): def test_a_line_the_head_changed_holds_no_bug(self): self.assertIsNone(bug_at_sides(self.MUTANT, "@@ -3 +3 @@\n-\treturn a + b\n+\treturn b + a\n", {"base": self.BASE, "head": self.BASE})) - def test_a_side_without_the_file_or_without_the_token_holds_no_bug(self): + def test_a_side_without_the_file_or_without_the_operator_the_mutant_changes_holds_no_bug(self): self.assertIsNone(bug_at_sides(self.MUTANT, "", {"base": self.BASE, "head": None})) self.assertIsNone(bug_at_sides(self.MUTANT, "", {"base": self.BASE, "head": b"package calc\n\n\treturn sum(a, b)\n"})) diff --git a/bin/task_bench/test_task_bench.py b/bin/task_bench/test_task_bench.py index 05ede27b..b42a85e2 100644 --- a/bin/task_bench/test_task_bench.py +++ b/bin/task_bench/test_task_bench.py @@ -232,7 +232,7 @@ class BenchTest(unittest.TestCase): def test_the_command_line_fails_with_the_reason_where_the_places_or_the_bench_fail(self): argv = [part for name, value in self.given.items() for part in (name, value)] - for places, said in ((Failure("no history"), "no history\n"), ("- `gone.go:1` `Gone`: removed\n", "The places the seats found hard name no Go file that the base holds, so there is nowhere to plant a bug.\n")): + for places, said in ((Failure("no history"), "no history\n"), ("- `gone.go:1` `Gone`: removed\n", "The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.\n")): with contextlib.redirect_stdout(io.StringIO()) as out, contextlib.redirect_stderr(io.StringIO()) as errors: self.assertEqual(main.main(argv, self.env, lambda home: places), 1) self.assertEqual((out.getvalue(), errors.getvalue().splitlines(keepends=True)[-1]), ("", said)) @@ -302,7 +302,7 @@ class BenchTest(unittest.TestCase): def test_fails_where_the_places_name_no_go_file_of_the_base(self): with contextlib.redirect_stderr(io.StringIO()): found = main.bench({**self.given, "--base": "main"}, self.env, "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home) - self.assertEqual(found, Failure("The places the seats found hard name no Go file that the base holds, so there is nowhere to plant a bug.")) + self.assertEqual(found, Failure("The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.")) self.assertFalse(self.log.exists()) def test_fails_where_the_tests_fail_without_a_bug(self): @@ -500,7 +500,7 @@ class RunOutcomesTest(unittest.TestCase): task = dataclasses.replace(self.task, trees={"base": str(self.folder / "gone"), "head": str(self.tree)}) self.assertFailsWith(main.fixed(task, "base", 1, self.containers(), self.folder), "could not copy bug 1's tree at the base: ") - def test_a_tree_that_checks_a_fix_that_cannot_be_made_fails_the_bench_naming_the_bug_and_side(self): + def test_failing_to_make_the_tree_that_checks_a_fix_fails_the_bench_naming_the_bug_and_side(self): (self.folder / "check").mkdir() self.assertFailsWith(main.fixed(self.task, "base", 1, self.containers(Ran(0, "")), self.folder), "could not make the tree that checks bug 1's fix at the base: ") diff --git a/todo.md b/todo.md index 9934733e..aa2e8c1b 100644 --- a/todo.md +++ b/todo.md @@ -109,8 +109,8 @@ This release changes what `task-bench`'s All change row means: it is now the mean of the bugs' own head/base changes, where 0.15.0 printed the change of the two All rows' medians. Semver read strictly lets only a minor change what exists before 1.0.0, so a patch can't ship it. The release review's architecture pass found this (`technical-principles.md`, "Semantic versioning, read strictly"). Two ways out: -- Ship this release as 0.16.0. Recommended: the old figure swung up to three times as far in tokens, so restoring it brings back a figure the release found misleading. -- Keep 0.15.1: restore the old row under its old label, add the new figure as a row of its own, and leave the new row's meaning for 0.16.0. +- Ship this release as 0.16.0. Recommended: with the same code at both sides, the old figure swung up to three times as far as the new one in tokens (`docs/decisions.md`, "Spread by bugs × runs"), so restoring it brings back a figure this release found misleading. +- Keep 0.15.1: restore the old row as 0.15.0 printed it, and ship the new figure in 0.16.0 instead. Adding the new figure as a row of its own is a minor change too, so it can't stay in 0.15.1. Touches: - `CHANGELOG.md`: `## Unreleased` (small)