From 0c52e51463a540b3449dc15d014d032c127f0376 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:28:09 +0100 Subject: [PATCH 01/14] Re-score item 442's L to 4 --- todo.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index 1a0f3271..08bc5ebf 100644 --- a/todo.md +++ b/todo.md @@ -15,7 +15,7 @@ | 420 | 0.12.0 | | | **End a worker that printed its final result and lingers, by killing the background shells it left, after a few minutes, and print each kill with its evidence on loop-claude's terminal.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 6 | 2.0 | | 414 | 0.12.0 | | | **DM the human through the notifier when a human-task issue blocks the epic's next item, and poll until it closes.** | 2 | 2 | 2 | 4 | 3 | 1 by 5 | 1.9 | | 417 | 0.12.0 | | | **Run do-epic end to end against a sandbox epic on a real Jira site with a command of its own, outside `run-tests`.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 | -| 442 | 0.12.0 | | | **Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 | +| 442 | 0.12.0 | | | **Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks.** | 4 | 2 | 3 | 7 | 5 | 1 by 5 | 1.2 | | 310 | 0.12.0 | | | **Compact a waiting worker's session shortly before its prompt cache expires, only when the human has not answered an interrupt by then.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 0.9 | | 422 | 0.12.0 | 420 | | **Check every 5 minutes whether a tmux window of the loop looks stuck by other signs than a lingering worker, investigate it with a headless claude, and kill only the process the investigation names.** | 3 | 2 | 3 | 6 | 5 | 1.5 by 4 | 0.8 | | 365 | 0.13.0 | | | **Have `score-outcomes` read the finished and dropped items of a plan outside the checkout, from the project repo's history or from Jira's issue changelogs.** | 3 | 2 | 2 | 5 | 4 | 1.6 by 2, 1.1 by 2 | 1.2 | @@ -113,6 +113,8 @@ Today `do-epic ` starts only an issue whose label already records its The README says today that do-epic doesn't pick or rank by itself (`README.md` → `## Tools`, `### Set up a project`); this item makes both true, so it rewords those two passages. +L is 4, two or more of level 3's: several components (`main`, a new planning module, a reader of each repo's goals file, decision log, comprehension history and readability floor through its project config, which do_epic lacks, and the terminal interrupt), live state (every step writes labels, sub-tasks, comments or backlog ranks in a client's Jira), and likely S 6 or more with its tests. It matches the L 4 anchors 96 and 148 and the do-epic items 375 and 410 more than the L 3 anchors. + Touches: - `bin/do_epic/main.py`: `windows_opened`, `chunks_started` -- 2.52.0 From 444f97a566991c2041abc1867c6e1b2225586101 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:28:49 +0100 Subject: [PATCH 02/14] Re-score item 442's S to 6 --- todo.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/todo.md b/todo.md index 08bc5ebf..d536cabc 100644 --- a/todo.md +++ b/todo.md @@ -15,9 +15,9 @@ | 420 | 0.12.0 | | | **End a worker that printed its final result and lingers, by killing the background shells it left, after a few minutes, and print each kill with its evidence on loop-claude's terminal.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 6 | 2.0 | | 414 | 0.12.0 | | | **DM the human through the notifier when a human-task issue blocks the epic's next item, and poll until it closes.** | 2 | 2 | 2 | 4 | 3 | 1 by 5 | 1.9 | | 417 | 0.12.0 | | | **Run do-epic end to end against a sandbox epic on a real Jira site with a command of its own, outside `run-tests`.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 | -| 442 | 0.12.0 | | | **Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks.** | 4 | 2 | 3 | 7 | 5 | 1 by 5 | 1.2 | | 310 | 0.12.0 | | | **Compact a waiting worker's session shortly before its prompt cache expires, only when the human has not answered an interrupt by then.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 0.9 | | 422 | 0.12.0 | 420 | | **Check every 5 minutes whether a tmux window of the loop looks stuck by other signs than a lingering worker, investigate it with a headless claude, and kill only the process the investigation names.** | 3 | 2 | 3 | 6 | 5 | 1.5 by 4 | 0.8 | +| 442 | 0.12.0 | | | **Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks.** | 4 | 2 | 3 | 7 | 6 | 1 by 5 | 0.8 | | 365 | 0.13.0 | | | **Have `score-outcomes` read the finished and dropped items of a plan outside the checkout, from the project repo's history or from Jira's issue changelogs.** | 3 | 2 | 2 | 5 | 4 | 1.6 by 2, 1.1 by 2 | 1.2 | | 368 | 0.13.0 | | | **Call a release review due, call a release ready to cut, and tell whether a chunk owes a scoring run, for a plan outside the checkout, from the project repo's history or from Jira.** | 3 | 2 | 2 | 5 | 4 | 1.6 by 2, 1.1 by 2 | 1.2 | | 309 | 0.13.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 | @@ -107,21 +107,6 @@ Touches: - `bin/do-epic-e2e` - `bin/do_epic/e2e/` -### 442. Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks. - -Today `do-epic ` starts only an issue whose label already records its repo, and prints that every other one waits (`bin/do_epic/scheduler.py` → `chunks`). `split.split`, `repo_pick.picked` and `ranking` exist and nothing calls them. Each is a headless claude call on a rung: route it on `repoless-model`'s rung of the shipped ladder. An `Unclear` pick is an interrupt on the terminal of the `do-epic ` the human runs. A chunk that finishes starts the next chunks without planning again, so no window waits on a question. - -The README says today that do-epic doesn't pick or rank by itself (`README.md` → `## Tools`, `### Set up a project`); this item makes both true, so it rewords those two passages. - -L is 4, two or more of level 3's: several components (`main`, a new planning module, a reader of each repo's goals file, decision log, comprehension history and readability floor through its project config, which do_epic lacks, and the terminal interrupt), live state (every step writes labels, sub-tasks, comments or backlog ranks in a client's Jira), and likely S 6 or more with its tests. It matches the L 4 anchors 96 and 148 and the do-epic items 375 and 410 more than the L 3 anchors. - -Touches: - -- `bin/do_epic/main.py`: `windows_opened`, `chunks_started` -- `bin/do_epic/planning.py` -- `bin/do_epic/test_main.py` -- `README.md`: `## Tools`, `### Set up a project` (small) - ### 310. Compact a waiting worker's session shortly before its prompt cache expires, only when the human has not answered an interrupt by then. 281 worker resumes after the 1-hour cache expired rewrote a whole context, $379 of the $9,154 measured from 2026-09-30 to 2026-11-11 (4.1%). A compaction while the cache is warm reads the context at a twentieth of the input price and leaves about 20k tokens to rewrite later. @@ -153,6 +138,21 @@ Touches: - `bin/agent_cycle/tmux.py`: `Listed`, `listed` - `README.md`: `## Tools` (small) +### 442. Have `do-epic ` split each open issue by repo, pick the repo of each issue that no label names one for, asking the human where unclear, and re-rank the epic, before it starts chunks. + +Today `do-epic ` starts only an issue whose label already records its repo, and prints that every other one waits (`bin/do_epic/scheduler.py` → `chunks`). `split.split`, `repo_pick.picked` and `ranking` exist and nothing calls them. Each is a headless claude call on a rung: route it on `repoless-model`'s rung of the shipped ladder. An `Unclear` pick is an interrupt on the terminal of the `do-epic ` the human runs. A chunk that finishes starts the next chunks without planning again, so no window waits on a question. + +The README says today that do-epic doesn't pick or rank by itself (`README.md` → `## Tools`, `### Set up a project`); this item makes both true, so it rewords those two passages. + +L is 4, two or more of level 3's: several components (`main`, a new planning module, a reader of each repo's goals file, decision log, comprehension history and readability floor through its project config, which do_epic lacks, and the terminal interrupt), live state (every step writes labels, sub-tasks, comments or backlog ranks in a client's Jira), and likely S 6 or more with its tests. It matches the L 4 anchors 96 and 148 and the do-epic items 375 and 410 more than the L 3 anchors. + +Touches: + +- `bin/do_epic/main.py`: `windows_opened`, `chunks_started` +- `bin/do_epic/planning.py` +- `bin/do_epic/test_main.py` +- `README.md`: `## Tools`, `### Set up a project` (small) + ### 365. Have `score-outcomes` read the finished and dropped items of a plan outside the checkout, from the project repo's history or from Jira's issue changelogs. lilleman's call, 2026-11-12: 0.10.0 and 0.11.0 switch the history tools off for a plan outside the checkout, and 0.13.0 holds only their ports. In Jira a dropped item, which `Drop item` commit titles mark today, is an issue resolved by a resolution the config names. -- 2.52.0 From 608e00b61939f1db39d5303b7826e88d102d8e82 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:33:09 +0100 Subject: [PATCH 03/14] Plan an epic's open issues before do-epic starts chunks --- README.md | 6 +- bin/do_epic/main.py | 19 +++- bin/do_epic/planning.py | 163 +++++++++++++++++++++++++++++++++ bin/do_epic/test_main.py | 40 +++++++- bin/do_epic/test_planning.py | 172 +++++++++++++++++++++++++++++++++++ 5 files changed, 390 insertions(+), 10 deletions(-) create mode 100644 bin/do_epic/planning.py create mode 100644 bin/do_epic/test_planning.py diff --git a/README.md b/README.md index 48979d0b..da92a539 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ The last line prints each setting's path once the config is complete. `do-epic` keeps its settings per machine, not per project, in `~/.claude-projects/do-epic/`, two files for every epic: - `config.toml` sets `jira-url`, the site, such as `https://acme.atlassian.net`; `env-file`, the file holding `ATLASSIAN_EMAIL` and `ATLASSIAN_API_TOKEN`, a path that starts with `/` or `~/`, outside the clone folder and every folder of `~/.claude-projects`; and `repoless-model`, the model that works an item with no repo. It may also set `clone-folder`, where a missing repo is cloned, `~/code` if left out; `language`, the language of Jira text, English if left out; and `jira-finish-transition` with `jira-finish-status`, which name the workflow transition that moves a finished chunk's issue, and closes a finished epic, and the status it leads to, such as `"Mark as done"` and `"Done"`. Set both or neither: without them do-epic moves no issue to done and closes no epic, and a chunk that finishes stops with that reason. -- `repo-rule.md` is prose that says how to tell an item's repo, such as "a label that equals a repo's name names that repo". It may not be blank. do-epic doesn't read it yet: until it picks each item's repo from the rule, an issue runs once a label `repo:` records its repo, `do-epic-claude` marks work of Claude's that changes no repo, and `do-epic-human` a task of yours. +- `repo-rule.md` is prose that says how to tell an item's repo, such as "a label that equals a repo's name names that repo". It may not be blank. `do-epic ` picks by it where each open issue is worked, and records the pick as a label: `repo:` for its repo, `do-epic-claude` for work of Claude's that changes no repo, and `do-epic-human` for a task of yours. Where the rule leaves an issue unclear, do-epic asks you on the terminal, and you answer with the label. Change a pick by editing the label in Jira. Each repo an epic changes has a project config of its own, as in the rest of this section. `do-epic` fails and names each setting or file that is missing or invalid. @@ -190,7 +190,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `command-patterns [] [--calls ]` prints a table of the shell command patterns a release's archived chunks ran, such as `tea pr create`, for an audit of the release, and with `--calls ` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys. - `compress-archives` gzips each transcript in loop-claude's archive and each file in the review folders 30 days after it last changed, keeping all of them; Install's crontab line runs it daily. - `deploy-release [--cut] []` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says. -- `do-epic ` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. An open issue runs once a label names its repo, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract. +- `do-epic ` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic files a sub-task per repo under each open issue that changes several, picks the repo of each other issue that no label names one for, asking you where that is unclear, and re-ranks the issues it filed, by the `Score = ...` line under the description's `## Scoring`. An open issue runs once a label names its repo, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract. - `judge-replay [--offline]` replays loop-claude's judge on archived verdicts of the projects run on the model. It prints what each rung a review climbs to misses, and the lowest rung below those that returns every verdict, as each candidate above it does. With `--offline` it doesn't call a judge: it counts what a "?" rule, a decision table and a classifier trained on the archive decide of each verdict's kind from the worker's final message, and how many interrupts each misses. `judge-replay --help` states both replays. - `larv-review ` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count and the opening of its round commit's title, the scoring run's trigger and setup; the comprehension history's format, its latest places and its count of how often seats agree; and each reviewer's prompt header. `larv-review --help` states them. `settings.json` → `hooks` runs `larv-review reviewer-context` as each subagent starts. A reviewer under `agents/` whose frontmatter has `omitClaudeMd: true` starts without `CLAUDE.md`, and the command hands it that file's "Shared goal", "Prose" and "Vocabulary" sections. - `loop-claude ` runs a project's next chunks, each in its own tmux window, cycle after cycle; `loop-claude --help` states its contract. @@ -224,7 +224,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`. -- `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`. `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. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. +- `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`. `planning.py` settles, before the chunks start, where each open issue is worked and the order of the loop's issues, through `split.py`, `repo_pick.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. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. - `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), and finds a pull request and reads its checks, once or until they settle (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` 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 `agent_cycle`'s judge and verdicts, and `loop_claude`'s premises, records and `ANSWER_DESTINATIONS`. diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 51649a69..63143312 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -1,6 +1,6 @@ """The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`). -`do-epic ` starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk `: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes. +`do-epic ` first plans the epic's open issues (`planning`): it splits each by repo, picks the repo of each that no label places, and re-ranks the loop's issues. Then it starts each of the epic's chunks that may start now, each in a window of the epic's tmux session, as `scheduler` picks them, and puts that session on the terminal. Each window runs `do-epic --chunk `: the cycles of one issue's chunk, run by the code that runs loop-claude's (`agent_cycle`), until the judge rules it finished. Then it starts the chunks that may start now, and its window closes. After each cycle of a chunk in a repo, the window reads what the chunk's pull request waits on (`gates`). While that is a gate only time or a person passes, the chunk is parked (`parked`): the window frees its running slot and polls the forge, and the chunk's next cycle starts once the worker has something to do and a slot is free. `do-epic --status` prints what each open issue does.""" import dataclasses @@ -9,7 +9,8 @@ import sys import typing from loop_claude.loop.chunk_start import archived_route, routed -from do_epic import chunk_prompt, findings, finish, gates, parked, scheduler, split, status +from do_epic import chunk_prompt, findings, finish, gates, parked, planning, scheduler, split, status +from claude_code.reply import Limited from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo from loop_claude.loop.close import closed_cycle from project_config.main import located as config_located @@ -46,8 +47,12 @@ HELP = f"""usage: do-epic [--status] {finish.USAGE} Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-. -An open issue of the epic runs as a chunk once it has a label and no issue blocks it. -The label names the issue's repo, or says the work changes no repo. +Before it starts chunks, do-epic plans each open issue that no label places: it files a sub-task +per repo where the issue changes several, and else labels it `repo:` for its repo, `do-epic-claude` +for work of Claude's that changes no repo, or `do-epic-human` for a task of yours, as repo-rule.md says. +Where the rule leaves that unclear, it asks you on the terminal, and you answer with the label. +It then ranks the issues it filed that hold scores, by the `Score = ...` line under the epic's ## Scoring. +An open issue runs as a chunk once it has such a label and no issue blocks it. As many run at once as the epic's description allows with a line such as `**Max parallel chunks:** 2`, one where it has none. A repo takes as many chunks as its `parallel-chunks`, and none while loop-claude runs chunks in it. A chunk whose worker ends its run while its pull request waits on its checks, an approval or a new review @@ -151,8 +156,12 @@ def epic_written(key: str, writes: tuple[str, str, tuple[str, ...]] | None, path def windows_opened(epic: EpicRun) -> Stop: - """What the do-epic the human runs does: starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches.""" + """What the do-epic the human runs does: plans the open issues (`planning`), starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches.""" issues = epic.store.read() + if not isinstance(issues, Failure): + issues = planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), issues) + if isinstance(issues, Limited): + return Stop(1, f"the epic is not planned, so no chunk started: {issues.said}") started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None) if isinstance(started, Failure): return Stop(1, started.reason) diff --git a/bin/do_epic/planning.py b/bin/do_epic/planning.py new file mode 100644 index 00000000..b5fd55d9 --- /dev/null +++ b/bin/do_epic/planning.py @@ -0,0 +1,163 @@ +"""What `do-epic ` settles before it starts chunks: where each open issue is worked, and the order the loop's issues come in (docs/decisions.md → `do-epic: drives one Jira epic …`). + +An open child issue that no label places is first split by repo (`split`), and where it changes one repo or none, its repo is picked (`repo_pick`). Each is a headless claude call on `repoless-model`'s rung of the shipped ladder. Where the repo rule leaves a pick unclear, the human answers on the terminal. Then the loop's issues are scored and Jira's backlog re-ranked to match (`ranking`). + +Only the do-epic the human runs plans. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question.""" +import dataclasses +import pathlib +import re + +from claude_code.reply import Limited +from do_epic import ranking, repo_pick, repos, split +from do_epic.backend.protocol import EpicIssue, EpicStore +from do_epic.config import DoEpicConfig +from do_epic.epic_record import EpicRecord +from do_epic.scheduler import STATE +from failure import Failure +from loop_effects.effects import Effects, say +from model_routing.ladder import Rung +from model_routing.ladder_file import read_ladder, SHIPPED +from plan.todo_table import Item +from plan_store.jira_epic import number +from plan_store.scoring import weighing_texts +from record_store.stores import goals_store, store as record_store + +# The epic's formula, stated under its `## Scoring` as a todo.md states its own. +FORMULA = re.compile(r"^`Score = ([^`]+)`$", re.M) +# An epic item has no release, and ranking wants every item of one epic in the same one. +NO_RELEASE = (0, 0, 0) + + +@dataclasses.dataclass(frozen=True) +class Planned: + """The epic whose open issues are planned.""" + key: str + config: DoEpicConfig + store: EpicStore + record: EpicRecord + home: pathlib.Path + effects: Effects + + +def planned(epic: Planned, issues: list[EpicIssue]) -> list[EpicIssue] | Failure | Limited: + """The epic's issues, read again after each open child issue that no label placed was split or got its pick, and the loop's issues were re-ranked. issues are the epic's, as just read. A Failure or a Limited says why the epic isn't planned; what was labelled, filed or ranked before it stays.""" + unplaced = [issue for issue in issues if issue.parent == epic.key and not issue.done and split.SPLIT_LABEL not in issue.labels and repo_pick.recorded(issue) is None] + if unplaced: + stopped = placed(epic, issues, unplaced) + if stopped is not None: + return stopped + read = epic.store.read() + if isinstance(read, Failure): + return read + issues = read + order = ranked_keys(epic, issues) + if isinstance(order, Failure): + return order + if [issue.key for issue in issues if issue.key in order] == order: + return issues + say(f"re-ranking the loop's issues in {epic.key}'s backlog", epic.effects, stdout=True) + refused = ranking.reranked(epic.store, order) + return refused or epic.store.read() + + +def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) -> None | Failure | Limited: + """Splits each of unplaced by repo, or labels it with its pick. An issue that claude or the tracker fails on is named and left for the next run, as is one whose question the human doesn't answer; a usage limit ends the planning.""" + rung = planning_rung(epic.config.repoless_model) + language = epic.record.language() + # Claude reads every repo a label of the epic names, a finished issue's too, to predict which of them an issue changes. + places = located(epic, [repo for issue in issues if isinstance(repo := repo_pick.recorded(issue), repo_pick.Repo)]) + if failed := next((each for each in (rung, language, places) if isinstance(each, Failure)), None): + return failed + assert isinstance(rung, Rung) and not isinstance(language, Failure) and isinstance(places, dict) + folder = epic.home / STATE / epic.key + folder.mkdir(parents=True, exist_ok=True) + checkouts = tuple(str(place.checkout) for place in places.values()) + for issue in unplaced: + say(f"planning {issue.key}", epic.effects, stdout=True) + parts = split.split(epic.store, issue, not issue.by_loop, epic.config.repo_rule, language or epic.config.language, checkouts, rung, epic.effects.claude, str(folder)) + if isinstance(parts, split.Split) and parts.repos: + say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True) + continue + pick = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.repo_rule, rung, epic.effects.claude, str(folder)) + if isinstance(pick, repo_pick.Unclear): + pick = answered(epic, issue, pick.question) + if isinstance(pick, Limited): + return pick + if isinstance(pick, Failure): + say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True) + elif pick is not None: + say(f"{issue.key} is labelled {repo_pick.label_of(pick)}", epic.effects, stdout=True) + return None + + +def planning_rung(model: str) -> Rung | Failure: + """The rung each planning call runs on: the model's cheapest on the shipped ladder.""" + ladder = read_ladder(SHIPPED) + if isinstance(ladder, Failure): + return ladder + project = ladder.project_rung(model) + return project.rung if project else Failure(f"`repoless-model` names {model}, which is not on the routing ladder {SHIPPED}") + + +def answered(epic: Planned, issue: EpicIssue, question: str) -> repo_pick.Pick | None | Failure: + """The pick the human types for an issue the repo rule leaves unclear, once it is recorded; None where nobody is at a terminal to answer, so the issue waits for the next run. The answer is the label to give the issue, so that it is spelt as a person would spell it in Jira.""" + if not epic.effects.on_terminal(): + say(f"{issue.key} waits for your answer: {question} Run `do-epic {epic.key}` on a terminal to answer, or label the issue in Jira.", epic.effects, stdout=True) + return None + say(f"\n{issue.key}, {issue.summary}: {question}", epic.effects) + while True: + try: + typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`: ") + except EOFError: + return None + pick = repo_pick.of_label(typed.strip()) + if pick is not None: + return repo_pick.record(epic.store, issue, pick) + say(f"`{typed.strip()}` is none of those labels", epic.effects) + + +def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Located] | Failure: + """Each picked repo's checkout and project config, by the repo's name.""" + places: dict[str, repos.Located] = {} + for name in sorted({pick.name for pick in picks}): + place = repos.locate(name, [each.checkout for each in places.values()], epic.config, epic.home, epic.effects.git) + if isinstance(place, Failure): + return place + places[name] = place + return places + + +def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure: + """The keys of the loop's open child issues that hold scores, in the order ranking gives them; empty where fewer than two do, since one issue has no order. Every other issue keeps its position, as a person's does: an issue nobody scored, one labelled with two picks, and an item split by repo, which has no one repo whose goals to score it by.""" + ours = [issue for issue in issues if issue.parent == epic.key and issue.by_loop and not issue.done and split.SPLIT_LABEL not in issue.labels and not isinstance(repo_pick.recorded(issue), Failure) and not ranking.unscored(item_of(issue, {}), issue.key)] + if len(ours) < 2: + return [] + numbers = {issue.key: number(issue.key) for issue in ours} + keys = {id_: key for key, id_ in numbers.items()} + if len(keys) < len(numbers): + return Failure(f"two of the loop's issues in the epic {epic.key} share a number in different Jira projects, so they cannot be ranked; move one of them") + scoring, goals = epic.record.section("Scoring"), epic.record.section("Goals") + if failed := next((each for each in (scoring, goals) if isinstance(each, Failure)), None): + return Failure(f"the epic {epic.key}'s description: {failed.reason}") + assert isinstance(scoring, str) and isinstance(goals, str) + formulas = FORMULA.findall(scoring) + if len(formulas) != 1: + return Failure(f"the epic {epic.key}'s description states `Score = ...` {len(formulas)} times under ## Scoring; state the formula that ranks its issues once, on a line of its own, such as `Score = 100 * V / (2**S + 32)`") + picks = {issue.key: repo_pick.recorded(issue) for issue in ours} + places = located(epic, [pick for pick in picks.values() if isinstance(pick, repo_pick.Repo)]) + if isinstance(places, Failure): + return places + rankings: dict[str, ranking.RepoRanking] = {} + for name, place in places.items(): + texts = weighing_texts(goals_store(place.config), record_store(place.config, "decisions"), record_store(place.config, "comprehension-history")) + if isinstance(texts, Failure): + return Failure(f"{name}: {texts.reason}") + rankings[name] = ranking.RepoRanking(*texts, place.config.readability_floor) + items = [ranking.EpicItem(item_of(issue, numbers), pick.name if isinstance(pick := picks[issue.key], repo_pick.Repo) else None) for issue in ours] + scored = ranking.ranked(items, formulas[0], goals, rankings) + return scored if isinstance(scored, Failure) else [keys[item.id] for item, _ in scored] + + +def item_of(issue: EpicIssue, numbers: dict[str, int]) -> Item: + """The issue as ranking scores it, blocked by each of its blockers among numbers, the issues ranked with it by key.""" + return Item(numbers.get(issue.key, 0), NO_RELEASE, issue.exempt, issue.summary, issue.scores, issue.moves, tuple(sorted(numbers[key] for key in issue.blockers if key in numbers))) diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index 3db0e95c..7c8edf71 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -34,6 +34,11 @@ from do_epic.test_do_epic import SETTINGS DESCRIPTION = "**Max parallel chunks:** 2\n\n## Goals\nShip the import.\n\n## Audience\nThe client's team.\n" +def structured(output: object, key: str | None = "structured_output") -> subprocess.CompletedProcess[str]: + """claude's reply that holds output as its structured answer; as the whole result event where key is None.""" + return subprocess.CompletedProcess([], 0, json.dumps({"type": "result", key: output} if key else output), "") + + @dataclasses.dataclass(frozen=True) class Description: """Stands in for an epic's description in Jira.""" @@ -52,7 +57,7 @@ class DoEpicTest(unittest.TestCase): folder.mkdir(parents=True) (folder / "config.toml").write_text(SETTINGS, encoding="utf-8") (folder / "repo-rule.md").write_text("A label that equals a repo's name names that repo.\n", encoding="utf-8") - self.issues = [issue("ABC-20"), dataclasses.replace(issue("ABC-21", "do-epic-claude"), detail="Tidy the docs.", scores={"L": 3, "E": 2, "I": 3})] + self.issues = [issue("ABC-20", "do-epic-human"), dataclasses.replace(issue("ABC-21", "do-epic-claude"), detail="Tidy the docs.", scores={"L": 3, "E": 2, "I": 3})] self.description: str | Failure = DESCRIPTION # What the forge answers each read of a chunk's gate, in turn; the last answers every later read. No worktree has the chunk's branch, so no chunk parks. self.forges = [Forge(worktrees="worktree /code/api\nbranch refs/heads/main\n")] @@ -126,12 +131,34 @@ class TheCommand(DoEpicTest): code, out, _ = self.run_main(["ABC-12"], fake, {"LOOP_CLAUDE_WORKER_MODEL": "m"}) self.assertEqual(code, 0) self.assertIn("started ABC-21 in the tmux session epic-ABC-12\n", out) - self.assertIn("ABC-20 waits: no label names its repo\n", out) + self.assertIn("ABC-20 waits: it is a human's task\n", out) started = [args for args in fake.tmux_calls if args[0] == "new-session"] self.assertEqual(started, [["new-session", "-d", "-s", "epic-ABC-12", "-n", "ABC-21", "-c", str(self.home / ".local/state/do-epic/ABC-12"), "-e", "LOOP_CLAUDE_WORKER_MODEL=m", "-e", "CHUNK_PR_PARKS=1", "-P", "-F", "#{window_id}", "--", "/b/do-epic", "--chunk", "ABC-21", "ABC-12"]]) # The session is no checkout's, so nothing marks it as one's. self.assertNotIn(tmux.OWNER, [args[3] for args in fake.tmux_calls if args[0] == "set-option"]) + def test_plans_an_issue_no_label_places_before_it_starts_the_chunks(self) -> None: + self.issues = [issue("ABC-20")] + fake = FakeEffects(on_terminal=False, claude=[structured({"parts": []}), structured({"pick": "claude"})]) + code, out, err = self.run_main(["ABC-12"], fake) + self.assertEqual(code, 0, err) + self.assertLess(out.index("ABC-20 is labelled do-epic-claude\n"), out.index("started ABC-20 in the tmux session epic-ABC-12\n")) + + def test_starts_no_chunk_where_a_usage_limit_ends_the_planning(self) -> None: + self.issues.append(issue("ABC-22")) + limit = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"} + fake = FakeEffects(claude=[structured(limit, None)]) + code, _, err = self.run_main(["ABC-12"], fake) + self.assertEqual(code, 1) + self.assertIn("the epic is not planned, so no chunk started: You've hit your limit\n", err) + self.assertEqual([args for args in fake.tmux_calls if args[0] == "new-session"], []) + + def test_stops_where_the_epic_cannot_be_planned(self) -> None: + self.issues = [dataclasses.replace(issue(key, "do-epic-claude"), scores={"L": 1, "E": 1, "I": 1, "S": 1}, by_loop=True) for key in ("ABC-20", "ABC-21")] + code, _, err = self.run_main(["ABC-12"], FakeEffects()) + self.assertEqual(code, 1) + self.assertIn("states `Score = ...` 0 times under ## Scoring", err) + def test_stops_on_an_epic_it_cannot_read(self) -> None: self.description = Failure("Jira answered 401") code, _, err = self.run_main(["ABC-12"], FakeEffects()) @@ -298,6 +325,15 @@ class TheHumansRun(DoEpicTest): class AChunksRun(DoEpicTest): + def test_a_finished_chunk_starts_the_next_without_planning_again(self) -> None: + self.issues.append(issue("ABC-22")) + fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows="ABC-21\t0\t@9\n") + code, out, err = self.run_main(["--chunk", "ABC-21", "ABC-12"], fake, MODELS) + self.assertEqual(code, 0, err) + self.assertIn("the chunk finished; started no other\n", out) + # The one claude call is the judge's: ABC-22, which no label places, waits for the human's do-epic. + self.assertEqual(len(fake.made("claude")), 1) + def test_runs_cycles_until_the_judge_rules_it_finished_then_starts_the_next_chunk(self) -> None: self.issues.append(issue("ABC-22", "do-epic-claude")) self.description = DESCRIPTION.replace("2", "1") diff --git a/bin/do_epic/test_planning.py b/bin/do_epic/test_planning.py new file mode 100644 index 00000000..4873bf8d --- /dev/null +++ b/bin/do_epic/test_planning.py @@ -0,0 +1,172 @@ +import contextlib +import dataclasses +import io +import json +import pathlib +import subprocess +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from claude_code.reply import Limited +from do_epic import planning +from do_epic.backend.fake import MemoryEpic +from do_epic.backend.protocol import EpicIssue +from do_epic.config import load +from do_epic.epic_record import EpicRecord +from do_epic.test_main import Description, DoEpicTest, structured as says +from do_epic.test_scheduler import issue +from failure import Failure +from loop_claude.test_loop_claude import FakeEffects +from plan.todo_table import parse_moves +from project_config.test_project_config import configured + +RANKED = "## Goals\n1. **Achieve:** Ship the import.\n\n## Audience\nThe client's team.\n\n## Scoring\n`Score = V`\n" +LIMIT = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"} + + +def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), by_loop: bool = True) -> EpicIssue: + """An open issue the loop filed, holding scores and moving the goals moves names.""" + parsed = parse_moves(key, moves) + assert not isinstance(parsed, Failure), parsed + return dataclasses.replace(issue(key, *labels, blockers=blockers), scores={"L": 1, "E": 1, "I": 1, "S": 1}, moves=parsed, by_loop=by_loop) + + +class Planning(DoEpicTest): + def plan(self, fake: FakeEffects) -> tuple[list[EpicIssue] | Failure | Limited, MemoryEpic, str]: + """What planning answers for self.issues, the store it changed and what it printed.""" + config = load(self.home) + assert not isinstance(config, Failure), config + store = MemoryEpic("ABC-12", list(self.issues)) + epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type] + out = io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out): + read = store.read() + assert not isinstance(read, Failure) + return planning.planned(epic, read), store, out.getvalue() + + def labels(self, store: MemoryEpic) -> dict[str, tuple[str, ...]]: + return {each.key: each.labels for each in store.issues} + + def test_an_issue_a_label_places_is_planned_without_claude(self) -> None: + self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "do-epic-claude"), issue("ABC-22", "split-by-repo"), issue("ABC-23", done=True)] + fake = FakeEffects() + found, _, out = self.plan(fake) + self.assertEqual((found, out, fake.made("claude")), (self.issues, "", [])) + + def test_labels_an_unplaced_issue_with_the_repo_claude_picks_on_the_repoless_models_rung(self) -> None: + self.issues = [issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": [{"repo": "api", "change": "Add the endpoint."}]}), says({"pick": "repo", "repo": "api"})]) + found, store, out = self.plan(fake) + self.assertEqual(found, [issue("ABC-20", "repo:api")]) + self.assertEqual(self.labels(store), {"ABC-20": ("repo:api",)}) + self.assertIn("ABC-20 is labelled repo:api\n", out) + for args, _ in fake.made("claude"): + self.assertEqual(args[args.index("--model") + 1], "claude-opus-5-5") + self.assertIn("A label that equals a repo's name names that repo.", fake.made("claude")[1][1]) + + def test_labels_work_without_a_repo_as_claudes_or_a_humans(self) -> None: + for pick, label in (("claude", "do-epic-claude"), ("human", "do-epic-human")): + with self.subTest(pick=pick): + self.issues = [issue("ABC-20")] + _, store, _ = self.plan(FakeEffects(claude=[says({"parts": []}), says({"pick": pick})])) + self.assertEqual(self.labels(store), {"ABC-20": (label,)}) + + def test_splits_an_issue_that_changes_several_repos_into_a_sub_task_for_each_and_picks_no_repo_for_it(self) -> None: + self.issues = [issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})]) + found, store, out = self.plan(fake) + assert not isinstance(found, Failure | Limited), found + self.assertEqual([(each.key, each.parent, each.labels) for each in found], [("ABC-20", "ABC-12", ("split-by-repo",)), ("ABC-101", "ABC-20", ("repo:api",)), ("ABC-102", "ABC-20", ("repo:web",))]) + # A person filed ABC-20, so the team is told. + self.assertEqual(store.comments, {"ABC-20": ["Split by repo: api and web."]}) + self.assertIn("ABC-20 is split into a sub-task for each of api, web\n", out) + + def test_the_split_reads_the_checkout_of_each_repo_a_label_of_the_epic_names(self) -> None: + checkout = self.home / "code" / "api" + configured(self, checkout, home=self.home) + self.issues = [issue("ABC-19", "repo:api", done=True), issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})]) + self.plan(fake) + args = fake.made("claude")[0][0] + self.assertEqual(args[args.index("--add-dir") + 1], str(checkout)) + + def test_asks_the_human_for_the_label_of_an_issue_the_rule_leaves_unclear_until_one_is_typed(self) -> None: + self.issues = [issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "unclear", "question": "Is the importer in api or in web?"})], inputs=["api", " repo:web "]) + found, store, out = self.plan(fake) + self.assertEqual(found, [issue("ABC-20", "repo:web")]) + self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", out) + self.assertIn("`api` is none of those labels\n", out) + self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:`, `do-epic-claude` or `do-epic-human`: "] * 2) + + def test_an_unclear_issue_waits_where_nobody_can_answer_and_the_next_is_planned(self) -> None: + unclear = says({"pick": "unclear", "question": "Is the importer in api or in web?"}) + for fake in (FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], on_terminal=False), FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], inputs=[EOFError()])): + with self.subTest(on_terminal=fake.terminal): + self.issues = [issue("ABC-20"), issue("ABC-21")] + _, store, out = self.plan(fake) + self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)}) + if not fake.terminal: + self.assertIn("ABC-20 waits for your answer: Is the importer in api or in web? Run `do-epic ABC-12` on a terminal to answer, or label the issue in Jira.\n", out) + + def test_an_issue_claude_fails_on_is_named_and_the_next_is_planned(self) -> None: + self.issues = [issue("ABC-20"), issue("ABC-21")] + fake = FakeEffects(claude=[subprocess.CompletedProcess([], 1, "", ""), says({"parts": []}), says({"pick": "claude"})]) + _, store, out = self.plan(fake) + self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)}) + self.assertIn("ABC-20 is not planned: the repo split exited 1\n", out) + + def test_a_usage_limit_ends_the_planning(self) -> None: + self.issues = [issue("ABC-20"), issue("ABC-21")] + fake = FakeEffects(claude=[subprocess.CompletedProcess([], 0, json.dumps(LIMIT), "")]) + found, _, _ = self.plan(fake) + self.assertIsInstance(found, Limited) + self.assertEqual(len(fake.made("claude")), 1) + + def test_re_ranks_the_loops_scored_issues_by_score_with_a_blocker_first_and_leaves_every_other_issue_in_place(self) -> None: + self.description = RANKED + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude", by_loop=False), scored("ABC-22", "epic 1 by 5", "do-epic-claude", blockers=("ABC-24",)), dataclasses.replace(issue("ABC-23", "do-epic-claude"), by_loop=True), scored("ABC-24", "epic 1 by 3", "do-epic-claude")] + found, store, out = self.plan(FakeEffects()) + assert not isinstance(found, Failure | Limited), found + # ABC-22 scores highest, and ABC-24 blocks it. ABC-21 is a person's, and nobody scored ABC-23. + self.assertEqual([each.key for each in found], ["ABC-24", "ABC-21", "ABC-22", "ABC-23", "ABC-20"]) + self.assertIn("re-ranking the loop's issues in ABC-12's backlog\n", out) + + def test_ranks_an_issue_in_a_repo_by_that_repos_goals_after_the_epics(self) -> None: + checkout = self.home / "code" / "api" + configured(self, checkout, home=self.home) + (checkout / "README.md").write_text("## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n", encoding="utf-8") + self.description = RANKED + self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] + found, _, _ = self.plan(FakeEffects()) + assert not isinstance(found, Failure | Limited), found + self.assertEqual([each.key for each in found], ["ABC-21", "ABC-20"]) + + def test_issues_already_in_their_order_are_not_ranked_again(self) -> None: + self.description = RANKED + self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), scored("ABC-21", "epic 1 by 2", "do-epic-claude")] + found, _, out = self.plan(FakeEffects()) + self.assertEqual((found, out), (self.issues, "")) + + def test_fails_where_the_epic_states_no_formula_to_rank_two_scored_issues_by(self) -> None: + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] + found, store, _ = self.plan(FakeEffects()) + self.assertEqual(found, Failure("the epic ABC-12's description states `Score = ...` 0 times under ## Scoring; state the formula that ranks its issues once, on a line of its own, such as `Score = 100 * V / (2**S + 32)`")) + self.assertEqual([each.key for each in store.issues], ["ABC-20", "ABC-21"]) + + def test_one_scored_issue_needs_no_formula(self) -> None: + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-claude")] + self.assertEqual(self.plan(FakeEffects())[0], self.issues) + + def test_fails_where_the_tracker_cannot_be_read_after_a_pick(self) -> None: + self.issues = [issue("ABC-20")] + + def failing(_: object) -> subprocess.CompletedProcess[str]: + self.store.fails = "Jira answered 503" + return says({"parts": []}) + config = load(self.home) + self.store = MemoryEpic("ABC-12", list(self.issues)) + epic = planning.Planned("ABC-12", config, self.store, EpicRecord(Description(self.description)), self.home, FakeEffects(claude=[failing, says({"pick": "claude"})]).effects()) # type: ignore[arg-type] + with contextlib.redirect_stdout(io.StringIO()): + self.assertEqual(planning.planned(epic, list(self.issues)), Failure("Jira answered 503")) -- 2.52.0 From 0d02a8383386c18dad68ca9eb5780cf5ecc553b8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:33:19 +0100 Subject: [PATCH 04/14] File the ranking of an epic item split by repo --- todo.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index d536cabc..bbf3900f 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 443` +`Next ID = 444` ## Items @@ -22,6 +22,7 @@ | 368 | 0.13.0 | | | **Call a release review due, call a release ready to cut, and tell whether a chunk owes a scoring run, for a plan outside the checkout, from the project repo's history or from Jira.** | 3 | 2 | 2 | 5 | 4 | 1.6 by 2, 1.1 by 2 | 1.2 | | 309 | 0.13.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 | | 419 | 0.13.0 | | | **Run the external auto-reviewer until its review of the PR's head has no findings, and answer each of its threads on the PR.** | 3 | 2 | 3 | 6 | 5 | 1.1 by 5 | 1.1 | +| 443 | 0.13.0 | | | **Rank an epic item that is split by repo, by the goals of each repo its sub-tasks name.** | 2 | 2 | 2 | 4 | 3 | 1 by 3 | 1.1 | | 366 | 0.13.0 | | | **Count the chunks of a project whose plan sits outside the checkout in the routing figures, from the project repo's history or from Jira.** | 3 | 2 | 2 | 5 | 4 | 1.6 by 2, 1.4 by 2 | 1.1 | | 339 | 0.13.0 | | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 3 | 1.0 | | 341 | 0.13.0 | | | **Hand each worker's claude a lower Read limit through `CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS`, kept only where replays of the archived review rounds find what two unchanged replays find.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3 | 1.0 | @@ -203,6 +204,16 @@ Today `larv-review` §3 → "Round cap" stops the auto-reviewer after two review The change touches `skills/larv-review/SKILL.md` "Re-entry", which the comprehension seats found hard to follow (Locality): make it easier to read while editing it. +### 443. Rank an epic item that is split by repo, by the goals of each repo its sub-tasks name. + +Today `bin/do_epic/planning.py` → `ranked_keys` leaves an item marked `split-by-repo` at its position in the backlog, as it leaves a person's issue: `ranking.ranked` scores an item in one repo's chain of goals, and a split item has several repos. Its sub-tasks follow it, so the whole change keeps whatever rank the item had when it was filed. + +Touches: + +- `bin/do_epic/planning.py`: `ranked_keys` +- `bin/do_epic/ranking.py`: `ranked` +- `bin/do_epic/test_planning.py` + ### 366. Count the chunks of a project whose plan sits outside the checkout in the routing figures, from the project repo's history or from Jira. One of 0.13.0's history ports, per lilleman's call of 2026-11-12. -- 2.52.0 From 285c4fa5ae27cb219c63a005bd63221b1a3ab4e4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:33:26 +0100 Subject: [PATCH 05/14] Record the reading cost --- docs/reading-cost.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 3c0fa85b..4f0b9416 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -2986,3 +2986,37 @@ Read most (opens and searches): - `bin/do_epic/backend/test_fake.py` 2 - `bin/do_epic/chunk_prompt.py` 2 - `bin/plan_store/jira_epic.py` 2 + +## Reading cost, chunk c47160c51529, finished 2026-11-19T01:39:51Z + +78528 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/do_epic/scheduler.py` 7 +- `bin/do_epic/main.py` 6 +- `bin/agent_cycle/tmux.py` 3 +- `bin/do_epic/test_main.py` 3 +- `CHANGELOG.md` 2 +- `README.md` 2 +- `docs/decisions.md` 2 +- `bin/agent_cycle/interrupt.py` 1 +- `bin/do_epic/parked.py` 1 +- `bin/do_epic/status.py` 1 + +## Reading cost, chunk ce3296c9c012, finished 2026-11-19T02:25:43Z + +87939 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/do_epic/main.py` 8 +- `bin/do_epic/test_main.py` 6 +- `bin/project_config/settings.py` 6 +- `bin/do_epic/chunk_prompt.py` 3 +- `bin/do_epic/test_scheduler.py` 2 +- `skills/larv-review/SKILL.md` 2 +- `README.md` 1 +- `bin/chunk_pr/main.py` 1 +- `bin/do_epic/findings.py` 1 +- `bin/do_epic/repos.py` 1 -- 2.52.0 From ed50d76f4cfa527ec22d56b50fbf644e7a2a252e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 03:41:16 +0100 Subject: [PATCH 06/14] Sort the planning imports and type the pick --- bin/do_epic/main.py | 7 +++---- bin/do_epic/planning.py | 26 +++++++++++++------------- bin/do_epic/test_finish.py | 2 +- bin/do_epic/test_planning.py | 16 ++++++++-------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 63143312..7f270bcc 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -10,7 +10,6 @@ import typing from loop_claude.loop.chunk_start import archived_route, routed from do_epic import chunk_prompt, findings, finish, gates, parked, planning, scheduler, split, status -from claude_code.reply import Limited from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo from loop_claude.loop.close import closed_cycle from project_config.main import located as config_located @@ -28,6 +27,7 @@ from loop_claude.project.model_choice import get_or_ask_models, Models from plan_store.jira_epic import ISSUE_KEY from do_epic.backend.jira import JiraEpic from agent_cycle.routing import judge_rung +from claude_code.reply import Limited from do_epic.repos import locate from loop_claude.loop.this_loop import Loop from loop_claude.loop.reload import LoopRun @@ -157,9 +157,8 @@ def epic_written(key: str, writes: tuple[str, str, tuple[str, ...]] | None, path def windows_opened(epic: EpicRun) -> Stop: """What the do-epic the human runs does: plans the open issues (`planning`), starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches.""" - issues = epic.store.read() - if not isinstance(issues, Failure): - issues = planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), issues) + read = epic.store.read() + issues = read if isinstance(read, Failure) else planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), read) if isinstance(issues, Limited): return Stop(1, f"the epic is not planned, so no chunk started: {issues.said}") started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None) diff --git a/bin/do_epic/planning.py b/bin/do_epic/planning.py index b5fd55d9..47ad8f3b 100644 --- a/bin/do_epic/planning.py +++ b/bin/do_epic/planning.py @@ -7,20 +7,20 @@ import dataclasses import pathlib import re -from claude_code.reply import Limited -from do_epic import ranking, repo_pick, repos, split -from do_epic.backend.protocol import EpicIssue, EpicStore from do_epic.config import DoEpicConfig -from do_epic.epic_record import EpicRecord -from do_epic.scheduler import STATE -from failure import Failure from loop_effects.effects import Effects, say -from model_routing.ladder import Rung -from model_routing.ladder_file import read_ladder, SHIPPED -from plan.todo_table import Item -from plan_store.jira_epic import number -from plan_store.scoring import weighing_texts +from do_epic.backend.protocol import EpicIssue, EpicStore +from do_epic.epic_record import EpicRecord +from failure import Failure from record_store.stores import goals_store, store as record_store +from plan.todo_table import Item +from claude_code.reply import Limited +from plan_store.jira_epic import number +from do_epic import ranking, repo_pick, repos, split +from model_routing.ladder_file import read_ladder, SHIPPED +from model_routing.ladder import Rung +from do_epic.scheduler import STATE +from plan_store.scoring import weighing_texts # The epic's formula, stated under its `## Scoring` as a todo.md states its own. FORMULA = re.compile(r"^`Score = ([^`]+)`$", re.M) @@ -78,14 +78,14 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) -> if isinstance(parts, split.Split) and parts.repos: say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True) continue - pick = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.repo_rule, rung, epic.effects.claude, str(folder)) + pick: repo_pick.Pick | repo_pick.Unclear | Failure | Limited | None = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.repo_rule, rung, epic.effects.claude, str(folder)) if isinstance(pick, repo_pick.Unclear): pick = answered(epic, issue, pick.question) if isinstance(pick, Limited): return pick if isinstance(pick, Failure): say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True) - elif pick is not None: + elif pick is not None and not isinstance(pick, repo_pick.Unclear): say(f"{issue.key} is labelled {repo_pick.label_of(pick)}", epic.effects, stdout=True) return None diff --git a/bin/do_epic/test_finish.py b/bin/do_epic/test_finish.py index bc20f481..4241d546 100644 --- a/bin/do_epic/test_finish.py +++ b/bin/do_epic/test_finish.py @@ -168,7 +168,7 @@ class TheFinishingChunk(DoEpicTest): self.assertIn(["/b/do-epic", "--chunk", "ABC-12", "ABC-12"], [args[-4:] for args in fake.tmux_calls]) def test_doesnt_start_while_an_issue_is_open_or_in_an_epic_without_issues(self) -> None: - for issues in ([issue("ABC-20", "do-epic-claude", done=True), issue("ABC-21")], []): + for issues in ([issue("ABC-20", "do-epic-claude", done=True), issue("ABC-21", "do-epic-human")], []): self.issues = issues fake = FakeEffects(on_terminal=False) code, out, _ = self.run_main(["ABC-12"], fake) diff --git a/bin/do_epic/test_planning.py b/bin/do_epic/test_planning.py index 4873bf8d..8c4c0ad8 100644 --- a/bin/do_epic/test_planning.py +++ b/bin/do_epic/test_planning.py @@ -8,18 +8,18 @@ import sys sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from claude_code.reply import Limited -from do_epic import planning -from do_epic.backend.fake import MemoryEpic -from do_epic.backend.protocol import EpicIssue -from do_epic.config import load -from do_epic.epic_record import EpicRecord +from project_config.test_project_config import configured from do_epic.test_main import Description, DoEpicTest, structured as says -from do_epic.test_scheduler import issue +from do_epic.backend.protocol import EpicIssue +from do_epic.epic_record import EpicRecord from failure import Failure from loop_claude.test_loop_claude import FakeEffects +from do_epic.test_scheduler import issue +from claude_code.reply import Limited +from do_epic.config import load +from do_epic.backend.fake import MemoryEpic from plan.todo_table import parse_moves -from project_config.test_project_config import configured +from do_epic import planning RANKED = "## Goals\n1. **Achieve:** Ship the import.\n\n## Audience\nThe client's team.\n\n## Scoring\n`Score = V`\n" LIMIT = {"type": "result", "is_error": True, "api_error_status": 429, "result": "You've hit your limit"} -- 2.52.0 From 59c02ef8d17fbbfce634c78886380751630743ef Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 04:02:58 +0100 Subject: [PATCH 07/14] =?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);=20no=20findin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 94b34e509fce5a62739df562ed2180636cf484dd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 04:04:32 +0100 Subject: [PATCH 08/14] Test what planning prints, asks and refuses --- bin/do_epic/test_planning.py | 85 +++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/bin/do_epic/test_planning.py b/bin/do_epic/test_planning.py index 8c4c0ad8..cca6c573 100644 --- a/bin/do_epic/test_planning.py +++ b/bin/do_epic/test_planning.py @@ -34,13 +34,13 @@ def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), b class Planning(DoEpicTest): def plan(self, fake: FakeEffects) -> tuple[list[EpicIssue] | Failure | Limited, MemoryEpic, str]: - """What planning answers for self.issues, the store it changed and what it printed.""" + """What planning answers for self.issues, the store it changed and what it printed on stdout. self.asked holds what it asked the human, on stderr.""" config = load(self.home) assert not isinstance(config, Failure), config store = MemoryEpic("ABC-12", list(self.issues)) epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type] - out = io.StringIO() - with contextlib.redirect_stdout(out), contextlib.redirect_stderr(out): + out, self.asked = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked): read = store.read() assert not isinstance(read, Failure) return planning.planned(epic, read), store, out.getvalue() @@ -81,6 +81,48 @@ class Planning(DoEpicTest): # A person filed ABC-20, so the team is told. self.assertEqual(store.comments, {"ABC-20": ["Split by repo: api and web."]}) self.assertIn("ABC-20 is split into a sub-task for each of api, web\n", out) + self.assertIn("in English, that tells the team why it is split by repo", fake.made("claude")[0][1]) + + def test_plans_the_issue_after_one_that_is_split(self) -> None: + self.issues = [issue("ABC-20"), issue("ABC-21")] + parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."}) + _, store, _ = self.plan(FakeEffects(claude=[parts, says({"parts": []}), says({"pick": "human"})])) + self.assertEqual(self.labels(store)["ABC-21"], ("do-epic-human",)) + + def test_writes_to_the_team_in_the_epics_language(self) -> None: + self.description = "**Language:** Swedish\n" + self.issues = [issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})]) + self.plan(fake) + self.assertIn("in Swedish, that tells the team why it is split by repo", fake.made("claude")[0][1]) + + def test_each_claude_call_runs_in_the_epics_state_folder(self) -> None: + self.issues = [issue("ABC-20")] + fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})]) + effects, folders = fake.effects(), [] + + def claude(args: object, cwd: str, stdin: object) -> object: + folders.append(cwd) + return effects.claude(args, cwd, stdin) # type: ignore[arg-type] + config = load(self.home) + epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description("")), self.home, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type] + with contextlib.redirect_stdout(io.StringIO()): + planning.planned(epic, list(self.issues)) + folder = self.home / ".local" / "state" / "do-epic" / "ABC-12" + self.assertEqual((folders, folder.is_dir()), ([str(folder)] * 2, True)) + + def test_a_model_off_the_routing_ladder_has_no_rung(self) -> None: + found = planning.planning_rung("claude-nope-1") + assert isinstance(found, Failure), found + self.assertIn("`repoless-model` names claude-nope-1, which is not on the routing ladder ", found.reason) + + def test_fails_where_a_labelled_repo_has_no_checkout_to_read(self) -> None: + self.issues = [issue("ABC-19", "repo:ghost"), issue("ABC-20")] + fake = FakeEffects() + found, _, _ = self.plan(fake) + assert isinstance(found, Failure), found + self.assertIn("ghost", found.reason) + self.assertEqual(fake.made("claude"), []) def test_the_split_reads_the_checkout_of_each_repo_a_label_of_the_epic_names(self) -> None: checkout = self.home / "code" / "api" @@ -96,8 +138,8 @@ class Planning(DoEpicTest): fake = FakeEffects(claude=[says({"parts": []}), says({"pick": "unclear", "question": "Is the importer in api or in web?"})], inputs=["api", " repo:web "]) found, store, out = self.plan(fake) self.assertEqual(found, [issue("ABC-20", "repo:web")]) - self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", out) - self.assertIn("`api` is none of those labels\n", out) + self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", self.asked.getvalue()) + self.assertIn("`api` is none of those labels\n", self.asked.getvalue()) self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:`, `do-epic-claude` or `do-epic-human`: "] * 2) def test_an_unclear_issue_waits_where_nobody_can_answer_and_the_next_is_planned(self) -> None: @@ -107,6 +149,7 @@ class Planning(DoEpicTest): self.issues = [issue("ABC-20"), issue("ABC-21")] _, store, out = self.plan(fake) self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)}) + self.assertNotIn("ABC-20 is labelled", out) if not fake.terminal: self.assertIn("ABC-20 waits for your answer: Is the importer in api or in web? Run `do-epic ABC-12` on a terminal to answer, or label the issue in Jira.\n", out) @@ -155,6 +198,38 @@ class Planning(DoEpicTest): self.assertEqual(found, Failure("the epic ABC-12's description states `Score = ...` 0 times under ## Scoring; state the formula that ranks its issues once, on a line of its own, such as `Score = 100 * V / (2**S + 32)`")) self.assertEqual([each.key for each in store.issues], ["ABC-20", "ABC-21"]) + def test_fails_where_the_formula_names_a_score_no_issue_holds(self) -> None: + self.description = RANKED.replace("Score = V", "Score = Q") + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] + self.assertIsInstance(self.plan(FakeEffects())[0], Failure) + + def test_fails_where_two_issues_to_rank_share_a_number(self) -> None: + self.description = RANKED + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("XYZ-20", "epic 1 by 9", "do-epic-claude")] + self.assertEqual(self.plan(FakeEffects())[0], Failure("two of the loop's issues in the epic ABC-12 share a number in different Jira projects, so they cannot be ranked; move one of them")) + + def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None: + self.description = Failure("Jira answered 503") + self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] + self.assertEqual(self.plan(FakeEffects())[0], Failure("the epic ABC-12's description: Jira answered 503")) + + def test_fails_naming_the_repo_whose_goals_cannot_be_read(self) -> None: + checkout = self.home / "code" / "api" + configured(self, checkout, home=self.home) + (checkout / "README.md").write_text("# api\n", encoding="utf-8") + self.description = RANKED + self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] + found = self.plan(FakeEffects())[0] + assert isinstance(found, Failure), found + self.assertTrue(found.reason.startswith("api: "), found.reason) + + def test_ranks_a_security_issue_first(self) -> None: + self.description = RANKED + self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), dataclasses.replace(scored("ABC-21", "epic 1 by 2", "do-epic-claude"), exempt="security")] + found = self.plan(FakeEffects())[0] + assert not isinstance(found, Failure | Limited), found + self.assertEqual([each.key for each in found], ["ABC-21", "ABC-20"]) + def test_one_scored_issue_needs_no_formula(self) -> None: self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-claude")] self.assertEqual(self.plan(FakeEffects())[0], self.issues) -- 2.52.0 From 999fca6f177d5f6e7e966c7d16b66a79c5b68752 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 04:23:53 +0100 Subject: [PATCH 09/14] Pin planning's progress line and the repo a goals failure names --- bin/do_epic/test_planning.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/do_epic/test_planning.py b/bin/do_epic/test_planning.py index cca6c573..33d4655e 100644 --- a/bin/do_epic/test_planning.py +++ b/bin/do_epic/test_planning.py @@ -60,6 +60,7 @@ class Planning(DoEpicTest): found, store, out = self.plan(fake) self.assertEqual(found, [issue("ABC-20", "repo:api")]) self.assertEqual(self.labels(store), {"ABC-20": ("repo:api",)}) + self.assertIn("planning ABC-20\n", out) self.assertIn("ABC-20 is labelled repo:api\n", out) for args, _ in fake.made("claude"): self.assertEqual(args[args.index("--model") + 1], "claude-opus-5-5") @@ -216,12 +217,12 @@ class Planning(DoEpicTest): def test_fails_naming_the_repo_whose_goals_cannot_be_read(self) -> None: checkout = self.home / "code" / "api" configured(self, checkout, home=self.home) - (checkout / "README.md").write_text("# api\n", encoding="utf-8") + (checkout / "README.md").unlink(missing_ok=True) self.description = RANKED self.issues = [scored("ABC-20", "repo 1 by 9", "repo:api"), scored("ABC-21", "epic 1 by 9", "do-epic-claude")] found = self.plan(FakeEffects())[0] assert isinstance(found, Failure), found - self.assertTrue(found.reason.startswith("api: "), found.reason) + self.assertRegex(found.reason, r"^api: .*missing or empty") def test_ranks_a_security_issue_first(self) -> None: self.description = RANKED -- 2.52.0 From 0ce3cc6ac6dd8f46a0c52d28b4390e690b177bfc Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 04:46:55 +0100 Subject: [PATCH 10/14] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(1=20misread);=20start=20chu?= =?UTF-8?q?nks=20after=20a=20partial=20planning=20and=20keep=20what=20plan?= =?UTF-8?q?ning=20wrote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++- bin/do_epic/findings.py | 6 +- bin/do_epic/main.py | 27 +++++--- bin/do_epic/planning.py | 80 ++++++++++++++-------- bin/do_epic/split.py | 6 +- bin/do_epic/test_findings.py | 4 +- bin/do_epic/test_main.py | 11 +-- bin/do_epic/test_planning.py | 124 +++++++++++++++++++++++++++------- bin/do_epic/test_scheduler.py | 2 +- bin/do_epic/test_split.py | 8 +-- 10 files changed, 192 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index da92a539..ad081e60 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,9 @@ The last line prints each setting's path once the config is complete. `do-epic` keeps its settings per machine, not per project, in `~/.claude-projects/do-epic/`, two files for every epic: - `config.toml` sets `jira-url`, the site, such as `https://acme.atlassian.net`; `env-file`, the file holding `ATLASSIAN_EMAIL` and `ATLASSIAN_API_TOKEN`, a path that starts with `/` or `~/`, outside the clone folder and every folder of `~/.claude-projects`; and `repoless-model`, the model that works an item with no repo. It may also set `clone-folder`, where a missing repo is cloned, `~/code` if left out; `language`, the language of Jira text, English if left out; and `jira-finish-transition` with `jira-finish-status`, which name the workflow transition that moves a finished chunk's issue, and closes a finished epic, and the status it leads to, such as `"Mark as done"` and `"Done"`. Set both or neither: without them do-epic moves no issue to done and closes no epic, and a chunk that finishes stops with that reason. -- `repo-rule.md` is prose that says how to tell an item's repo, such as "a label that equals a repo's name names that repo". It may not be blank. `do-epic ` picks by it where each open issue is worked, and records the pick as a label: `repo:` for its repo, `do-epic-claude` for work of Claude's that changes no repo, and `do-epic-human` for a task of yours. Where the rule leaves an issue unclear, do-epic asks you on the terminal, and you answer with the label. Change a pick by editing the label in Jira. +- `repo-rule.md` is prose that says how to tell an item's repo, such as "a label that equals a repo's name names that repo". It may not be blank. `do-epic ` uses it to pick where each open issue without such a label is worked, and records the pick as a label: `repo:` for its repo, `do-epic-claude` for work of Claude's that changes no repo, and `do-epic-human` for a task of yours. Where the rule leaves an issue unclear, do-epic asks you on the terminal. Answer with the label, or with Enter alone to leave the issue waiting. Change a pick by editing the label in Jira. + +An epic's description states the formula that ranks the issues do-epic files in it: once under `## Scoring`, on a line of its own and inside backticks, such as `` `Score = 100 * V / (2**S + 32)` ``. Without that line do-epic says so and leaves the backlog's order as it is. Each repo an epic changes has a project config of its own, as in the rest of this section. `do-epic` fails and names each setting or file that is missing or invalid. @@ -190,7 +192,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `command-patterns [] [--calls ]` prints a table of the shell command patterns a release's archived chunks ran, such as `tea pr create`, for an audit of the release, and with `--calls ` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys. - `compress-archives` gzips each transcript in loop-claude's archive and each file in the review folders 30 days after it last changed, keeping all of them; Install's crontab line runs it daily. - `deploy-release [--cut] []` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says. -- `do-epic ` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic files a sub-task per repo under each open issue that changes several, picks the repo of each other issue that no label names one for, asking you where that is unclear, and re-ranks the issues it filed, by the `Score = ...` line under the description's `## Scoring`. An open issue runs once a label names its repo, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract. +- `do-epic ` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic plans each open issue that no label places yet, as "Set up a project" says. It files a sub-task per repo where the issue changes several repos. Otherwise it labels the issue with where it is worked, and asks you where that is unclear. Then it puts the scored issues that do-epic itself filed in order of score. An open issue runs once a label names its repo or marks it as Claude's, in Jira's backlog order, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract. - `judge-replay [--offline]` replays loop-claude's judge on archived verdicts of the projects run on the model. It prints what each rung a review climbs to misses, and the lowest rung below those that returns every verdict, as each candidate above it does. With `--offline` it doesn't call a judge: it counts what a "?" rule, a decision table and a classifier trained on the archive decide of each verdict's kind from the worker's final message, and how many interrupts each misses. `judge-replay --help` states both replays. - `larv-review ` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count and the opening of its round commit's title, the scoring run's trigger and setup; the comprehension history's format, its latest places and its count of how often seats agree; and each reviewer's prompt header. `larv-review --help` states them. `settings.json` → `hooks` runs `larv-review reviewer-context` as each subagent starts. A reviewer under `agents/` whose frontmatter has `omitClaudeMd: true` starts without `CLAUDE.md`, and the command hands it that file's "Shared goal", "Prose" and "Vocabulary" sections. - `loop-claude ` runs a project's next chunks, each in its own tmux window, cycle after cycle; `loop-claude --help` states its contract. @@ -224,7 +226,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`. -- `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`. `planning.py` settles, before the chunks start, where each open issue is worked and the order of the loop's issues, through `split.py`, `repo_pick.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. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. +- `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`. `planning.py` settles, before the chunks start, where each open issue is worked and the order of the issues do-epic filed, through `split.py`, `repo_pick.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. `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `finish.py` ends an epic that holds no open issue: its finishing chunk files a release review of each repo the epic changed, has the human confirm each goal, and with `--close-epic` posts the summary on the epic and closes it. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, posts comments, moves a finished chunk's issue to done, and closes the epic. - `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), and finds a pull request and reads its checks, once or until they settle (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` 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 `agent_cycle`'s judge and verdicts, and `loop_claude`'s premises, records and `ANSWER_DESTINATIONS`. diff --git a/bin/do_epic/findings.py b/bin/do_epic/findings.py index 92336512..54a11837 100644 --- a/bin/do_epic/findings.py +++ b/bin/do_epic/findings.py @@ -24,7 +24,7 @@ DECISIONS_LOCK = "decisions.lock" USAGE = f"""do-epic {FILE} [{LABEL}