Answer stability round 1: 0 🔴, 5 🟡 (1 misread); start chunks after a partial planning and keep what planning wrote

This commit is contained in:
2026-11-19 04:46:55 +01:00
parent 999fca6f17
commit 0ce3cc6ac6
10 changed files with 192 additions and 84 deletions
+5 -3
View File
@@ -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: `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. - `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 <EPIC-KEY>` picks by it where each open issue is worked, and records the pick as a label: `repo:<name>` 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 <EPIC-KEY>` uses it to pick where each open issue without such a label is worked, and records the pick as a label: `repo:<name>` 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. 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 [<version>] [--calls <file>]` 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 <file>` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys. - `command-patterns [<version>] [--calls <file>]` 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 <file>` 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. - `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] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says. - `deploy-release [--cut] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says.
- `do-epic <EPIC-KEY>` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-<EPIC-KEY>`, 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 <EPIC-KEY>` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-<EPIC-KEY>`, 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 <model> [--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. - `judge-replay <model> [--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 <command>` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count 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. - `larv-review <command>` holds larv-review's mechanical rules: the chunk's review folder, the paired ruling's base and vote count, each pass's round count 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 <task>` runs a project's next chunks, each in its own tmux window, cycle after cycle; `loop-claude --help` states its contract. - `loop-claude <task>` 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. - `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`. - `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`. - `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`. - `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`). - `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`. - `judge_replay` imports `agent_cycle`'s judge and verdicts, and `loop_claude`'s premises, records and `ANSWER_DESTINATIONS`.
+3 -3
View File
@@ -24,7 +24,7 @@ DECISIONS_LOCK = "decisions.lock"
USAGE = f"""do-epic <EPIC-KEY> {FILE} <summary> [{LABEL} <label>]... [<<'EOF' detail EOF] USAGE = f"""do-epic <EPIC-KEY> {FILE} <summary> [{LABEL} <label>]... [<<'EOF' detail EOF]
do-epic <EPIC-KEY> {RECORD_DECISION} <title> <<'EOF' entry EOF""" do-epic <EPIC-KEY> {RECORD_DECISION} <title> <<'EOF' entry EOF"""
HELP = f"""{FILE} files a finding about one of the epic's goals as an open issue of the epic, with the markdown piped in as its description. HELP = f"""{FILE} files a finding about one of the epic's goals as an open issue of the epic, with the markdown piped in as its description.
{LABEL} is {LABELS}; without one the issue waits until someone labels it. {LABEL} is {LABELS}; without one, the next `do-epic <EPIC-KEY>` you run picks where the issue is worked.
A second {LABEL}, `{REVIEW_LABEL}`, marks the issue as a repo's release review, which the epic's finishing files. A second {LABEL}, `{REVIEW_LABEL}`, marks the issue as a repo's release review, which the epic's finishing files.
A finding about a repo's own goals goes into that repo's plan instead. A finding about a repo's own goals goes into that repo's plan instead.
{RECORD_DECISION} appends a decision that governs the epic to its description's ## Decisions, under the title, with the markdown piped in as its text.""" {RECORD_DECISION} appends a decision that governs the epic to its description's ## Decisions, under the title, with the markdown piped in as its text."""
@@ -34,7 +34,7 @@ def instructions(epic: str, launcher: pathlib.Path, language: str) -> str:
"""What a chunk's first prompt says about filing a finding and recording a decision in the epic with the key epic. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in.""" """What a chunk's first prompt says about filing a finding and recording a decision in the epic with the key epic. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in."""
return ( return (
f"File a finding about one of the epic's goals in the epic, with `{launcher} {epic} {FILE} \"<summary>\" {LABEL} <label>` and its detail on stdin. " f"File a finding about one of the epic's goals in the epic, with `{launcher} {epic} {FILE} \"<summary>\" {LABEL} <label>` and its detail on stdin. "
f"The label is {LABELS}; leave it out where you cannot tell, and the issue waits for the human. " f"The label is {LABELS}; leave it out where you cannot tell, and the next `do-epic` the human runs picks it. "
"Where filing fails and says the issue may exist, ask the human to look before you file it again. " "Where filing fails and says the issue may exist, ask the human to look before you file it again. "
"File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. " "File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
f"Record a decision that governs the epic, such as an answer the human typed, with `{launcher} {epic} {RECORD_DECISION} \"<title>\"` and its text on stdin. " f"Record a decision that governs the epic, such as an answer the human typed, with `{launcher} {epic} {RECORD_DECISION} \"<title>\"` and its text on stdin. "
@@ -79,7 +79,7 @@ def written(epic: str, flag: str, value: str, labels: tuple[str, ...], store: Ep
key = store.file(epic, value, text, labels) key = store.file(epic, value, text, labels)
if isinstance(key, Failure): if isinstance(key, Failure):
return Failure(f"cannot file the finding in the epic {epic}: {key.reason}") return Failure(f"cannot file the finding in the epic {epic}: {key.reason}")
return f"Filed {key} in the epic {epic}." + ("" if any(of_label(label) for label in labels) else f" It waits until someone labels it: {LABELS}.") return f"Filed {key} in the epic {epic}." + ("" if any(of_label(label) for label in labels) else f" It has no label that says where it is worked, so the next `do-epic {epic}` picks one: {LABELS}.")
try: try:
with decisions_locked(folder): with decisions_locked(folder):
added = record.append_decision(value, text) added = record.append_decision(value, text)
+16 -11
View File
@@ -1,6 +1,6 @@
"""The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`). """The do-epic command (docs/decisions.md → `do-epic: drives one Jira epic …`).
`do-epic <EPIC-KEY>` 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 <ISSUE-KEY> <EPIC-KEY>`: 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 <EPIC-KEY>` first plans the epic's open issues (`planning`): each that no label places is split by repo or gets its pick, and the scored issues do-epic filed are re-ranked. 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 <ISSUE-KEY> <EPIC-KEY>`: 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 <EPIC-KEY> --status` prints what each open issue does.""" 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 <EPIC-KEY> --status` prints what each open issue does."""
import dataclasses import dataclasses
@@ -47,12 +47,12 @@ HELP = f"""usage: do-epic <EPIC-KEY> [--status]
{finish.USAGE} {finish.USAGE}
Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-<EPIC-KEY>. Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-<EPIC-KEY>.
Before it starts chunks, do-epic <EPIC-KEY> plans each open issue that no label places: it files a sub-task Before it starts chunks, do-epic <EPIC-KEY> plans each open issue that has none of these labels:
per repo where the issue changes several, and else labels it `repo:<name>` for its repo, `do-epic-claude` `repo:<name>` for its repo, `do-epic-claude` for work of Claude's that changes no repo, `do-epic-human` for a task of yours.
for work of Claude's that changes no repo, or `do-epic-human` for a task of yours, as repo-rule.md says. Where such an issue changes several repos, it files a sub-task per repo. Otherwise it gives the issue its label, as repo-rule.md says.
Where the rule leaves that unclear, it asks you on the terminal, and you answer with the label. Where the rule leaves the label unclear, it asks you on the terminal. Answer with the label, or with Enter alone to leave the issue waiting.
It then ranks the issues it filed that hold scores, by the `Score = ...` line under the epic's ## Scoring. It then puts the scored issues that do-epic itself filed in order of score, 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. An open issue labelled `repo:<name>` or `do-epic-claude` runs as a chunk once 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. 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 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 A chunk whose worker ends its run while its pull request waits on its checks, an approval or a new review
@@ -158,10 +158,15 @@ def epic_written(key: str, writes: tuple[str, str, tuple[str, ...]] | None, path
def windows_opened(epic: EpicRun) -> Stop: 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.""" """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."""
read = epic.store.read() 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(read, Failure):
if isinstance(issues, Limited): return Stop(1, read.reason)
return Stop(1, f"the epic is not planned, so no chunk started: {issues.said}") issues, stopped = planning.planned(planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.effects), read)
started = issues if isinstance(issues, Failure) else chunks_started(epic, issues, None) if isinstance(stopped, Limited):
return Stop(1, f"the epic is not planned, so no chunk started: {stopped.said}")
if stopped is not None:
# One issue or repo that cannot be planned holds back only itself: each chunk that may start still does.
say(f"the epic {epic.key} is not planned in full: {stopped.reason}", epic.effects)
started = chunks_started(epic, issues, None)
if isinstance(started, Failure): if isinstance(started, Failure):
return Stop(1, started.reason) return Stop(1, started.reason)
say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else "started no chunk", epic.effects, stdout=True) say(f"started {', '.join(started.started)} in the tmux session {epic.session}" if started.started else "started no chunk", epic.effects, stdout=True)
+52 -28
View File
@@ -1,8 +1,10 @@
"""What `do-epic <EPIC-KEY>` 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 …`). """What `do-epic <EPIC-KEY>` 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`). 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 issues do-epic filed 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.""" Planning runs only in the `do-epic <EPIC-KEY>` the human starts. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question.
Planning holds no lock: one `do-epic <EPIC-KEY>` at a time is assumed. A second one started meanwhile finds the sub-tasks the first filed, since `split` reads them before it files, unless Jira's search lags."""
import dataclasses import dataclasses
import pathlib import pathlib
import re import re
@@ -39,29 +41,41 @@ class Planned:
effects: Effects effects: Effects
def planned(epic: Planned, issues: list[EpicIssue]) -> list[EpicIssue] | Failure | Limited: def planned(epic: Planned, issues: list[EpicIssue]) -> tuple[list[EpicIssue], Failure | Limited | None]:
"""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.""" """The epic's issues as far as they are planned, and why the planning stopped early, None where it didn't. issues are the epic's, as just read.
Each open child issue that no label places is split or gets its pick. Then the issues do-epic filed are re-ranked. What was labelled, filed or ranked before a Failure or a Limited stays, and the issues returned show it."""
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] 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: added: dict[str, str] = {}
stopped = placed(epic, issues, unplaced) stopped = placed(epic, issues, unplaced, added) if unplaced else None
if stopped is not None: if added:
return stopped
read = epic.store.read() read = epic.store.read()
if isinstance(read, Failure): # A search may not show a label added a moment ago, so each label added here counts whatever the read says. A sub-task the search doesn't show yet starts on the next run.
return read issues = [labelled(each, added.get(each.key)) for each in (issues if isinstance(read, Failure) else read)]
issues = read stopped = stopped or (read if isinstance(read, Failure) else None)
if stopped is not None:
return issues, stopped
order = ranked_keys(epic, issues) order = ranked_keys(epic, issues)
if isinstance(order, Failure): if isinstance(order, Failure):
return order return issues, order
if [issue.key for issue in issues if issue.key in order] == order: if [issue.key for issue in issues if issue.key in order] == order:
return issues return issues, None
say(f"re-ranking the loop's issues in {epic.key}'s backlog", epic.effects, stdout=True) say(f"re-ranking the issues do-epic filed in {epic.key}'s backlog", epic.effects, stdout=True)
refused = ranking.reranked(epic.store, order) refused = ranking.reranked(epic.store, order)
return refused or epic.store.read() if refused:
return issues, refused
# A search may not show the new order yet, so the issues are put in it here, as `reranked` put them in Jira: each ranked issue in a position a ranked issue held.
by_key, ranked = {issue.key: issue for issue in issues}, iter(order)
return [by_key[next(ranked)] if issue.key in order else issue for issue in issues], None
def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) -> None | Failure | Limited: def labelled(issue: EpicIssue, label: str | None) -> EpicIssue:
"""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.""" """issue with label among its labels; issue itself where label is None."""
return issue if label is None or label in issue.labels else dataclasses.replace(issue, labels=tuple(sorted((*issue.labels, label))))
def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue], added: dict[str, str]) -> None | Failure | Limited:
"""Splits each of unplaced by repo, or labels it with its pick, and notes in added the label each got, by its key. 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) rung = planning_rung(epic.config.repoless_model)
language = epic.record.language() 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. # Claude reads every repo a label of the epic names, a finished issue's too, to predict which of them an issue changes.
@@ -76,6 +90,7 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
say(f"planning {issue.key}", epic.effects, stdout=True) 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)) 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: if isinstance(parts, split.Split) and parts.repos:
added[issue.key] = split.SPLIT_LABEL
say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True) say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True)
continue continue
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)) 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))
@@ -86,7 +101,8 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
if isinstance(pick, Failure): if isinstance(pick, Failure):
say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True) say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True)
elif pick is not None and not isinstance(pick, repo_pick.Unclear): 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) added[issue.key] = repo_pick.label_of(pick)
say(f"{issue.key} is labelled {added[issue.key]}", epic.effects, stdout=True)
return None return None
@@ -100,20 +116,26 @@ def planning_rung(model: str) -> Rung | Failure:
def answered(epic: Planned, issue: EpicIssue, question: str) -> repo_pick.Pick | None | Failure: 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.""" """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, or the human answers with Enter alone, 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.
A repo's name is not checked against the repos do-epic knows: an epic's first issue in a repo names one it has not seen."""
if not epic.effects.on_terminal(): 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) 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 return None
say(f"\n{issue.key}, {issue.summary}: {question}", epic.effects) say(f"\n{issue.key}, {issue.summary}: {question}", epic.effects)
while True: while True:
try: try:
typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}<name>`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`: ") typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}<name>`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`, or Enter alone to leave it waiting: ")
except EOFError: except EOFError:
return None return None
pick = repo_pick.of_label(typed.strip()) label = typed.strip()
if not label:
return None
pick = repo_pick.of_label(label)
if pick is not None: if pick is not None:
return repo_pick.record(epic.store, issue, pick) return repo_pick.record(epic.store, issue, pick)
say(f"`{typed.strip()}` is none of those labels", epic.effects) named = f"; the repo {label}'s label is `{repo_pick.REPO_PREFIX}{label}`" if repo_pick.of_label(repo_pick.REPO_PREFIX + label) else ""
say(f"`{label}` is none of those labels{named}", epic.effects)
def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Located] | Failure: def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Located] | Failure:
@@ -128,21 +150,23 @@ def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Locat
def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure: 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.""" """The keys of the open child issues do-epic filed that hold scores and one pick, in the order ranking gives them; empty where fewer than two do, since one issue has no order.
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)]
Every other issue keeps its position: a person's issue, one nobody scored, one with no pick yet or with two, and an item split by repo, since several repos' goals would score it."""
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 (pick := repo_pick.recorded(issue)) is not None and not isinstance(pick, Failure) and not ranking.unscored(item_of(issue, {}), issue.key)]
if len(ours) < 2: if len(ours) < 2:
return [] return []
numbers = {issue.key: number(issue.key) for issue in ours} numbers = {issue.key: number(issue.key) for issue in ours}
keys = {id_: key for key, id_ in numbers.items()} keys = {id_: key for key, id_ in numbers.items()}
if len(keys) < len(numbers): if clash := next(((key, keys[id_]) for key, id_ in numbers.items() if keys[id_] != key), None):
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") return Failure(f"{clash[0]} and {clash[1]} share a number in different Jira projects, so the issues do-epic filed in the epic {epic.key} cannot be ranked; move one of the two to the other's Jira project")
scoring, goals = epic.record.section("Scoring"), epic.record.section("Goals") scoring, goals = epic.record.section("Scoring"), epic.record.section("Goals")
if failed := next((each for each in (scoring, goals) if isinstance(each, Failure)), None): 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}") return Failure(f"the epic {epic.key}'s description: {failed.reason}")
assert isinstance(scoring, str) and isinstance(goals, str) assert isinstance(scoring, str) and isinstance(goals, str)
formulas = FORMULA.findall(scoring) formulas = FORMULA.findall(scoring)
if len(formulas) != 1: 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)`") 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 and inside backticks, such as `Score = 100 * V / (2**S + 32)`")
picks = {issue.key: repo_pick.recorded(issue) for issue in ours} 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)]) places = located(epic, [pick for pick in picks.values() if isinstance(pick, repo_pick.Repo)])
if isinstance(places, Failure): if isinstance(places, Failure):
@@ -159,5 +183,5 @@ def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
def item_of(issue: EpicIssue, numbers: dict[str, int]) -> Item: 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.""" """The issue as ranking scores it. numbers holds the number of each issue ranked with it, by key; the item is blocked by those of them that block the issue."""
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))) 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)))
+3 -3
View File
@@ -84,14 +84,14 @@ def split(store: EpicStore, issue: EpicIssue, by_person: bool, rule: str, langua
continue continue
key = store.file(issue.key, task_summary(part.repo, issue.summary), part.change, (label_of(Repo(part.repo)),)) key = store.file(issue.key, task_summary(part.repo, issue.summary), part.change, (label_of(Repo(part.repo)),))
if isinstance(key, Failure): if isinstance(key, Failure):
return Failure(f"cannot file the sub-task for {part.repo} under {issue.key}: {key.reason}; {sub_tasks_filed(filed)}; run split again to file the rest") return Failure(f"cannot file the sub-task for {part.repo} under {issue.key}: {key.reason}; {sub_tasks_filed(filed)}; run do-epic again to file the rest")
filed.append(key) filed.append(key)
posted = store.comment(issue.key, predicted.comment) if by_person else None posted = store.comment(issue.key, predicted.comment) if by_person else None
if isinstance(posted, Failure): if isinstance(posted, Failure):
return Failure(f"cannot comment on {issue.key}: {posted.reason}; {sub_tasks_filed(filed)}; run split again to post it") return Failure(f"cannot comment on {issue.key}: {posted.reason}; {sub_tasks_filed(filed)}; run do-epic again to post it")
marked = store.add_label(issue.key, SPLIT_LABEL) marked = store.add_label(issue.key, SPLIT_LABEL)
if isinstance(marked, Failure): if isinstance(marked, Failure):
return Failure(f"cannot mark {issue.key} as split: {marked.reason}; {sub_tasks_filed(filed)}; run split again to mark it") return Failure(f"cannot mark {issue.key} as split: {marked.reason}; {sub_tasks_filed(filed)}; run do-epic again to mark it")
return Split(repos, tuple(filed)) return Split(repos, tuple(filed))
+2 -2
View File
@@ -70,7 +70,7 @@ class FindingsTest(DoEpicTest):
class FilingAFinding(FindingsTest): class FilingAFinding(FindingsTest):
def test_files_an_issue_under_the_epic_with_the_detail_piped_in_and_doesnt_start_anything(self) -> None: def test_files_an_issue_under_the_epic_with_the_detail_piped_in_and_doesnt_start_anything(self) -> None:
code, out, err, fake = self.run_with(["ABC-12", "--file", "Retry the import on a 503"], "The client times out.\n") code, out, err, fake = self.run_with(["ABC-12", "--file", "Retry the import on a 503"], "The client times out.\n")
self.assertEqual((code, out, err), (0, "Filed ABC-102 in the epic ABC-12. It waits until someone labels it: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n", "")) self.assertEqual((code, out, err), (0, "Filed ABC-102 in the epic ABC-12. It has no label that says where it is worked, so the next `do-epic ABC-12` picks one: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n", ""))
self.assertEqual(self.keys, ["ABC-12"]) self.assertEqual(self.keys, ["ABC-12"])
filed = self.store.issues[-1] filed = self.store.issues[-1]
self.assertEqual((filed.key, filed.summary, filed.detail, filed.labels, filed.parent, filed.by_loop), ("ABC-102", "Retry the import on a 503", "The client times out.", (), "ABC-12", True)) self.assertEqual((filed.key, filed.summary, filed.detail, filed.labels, filed.parent, filed.by_loop), ("ABC-102", "Retry the import on a 503", "The client times out.", (), "ABC-12", True))
@@ -88,7 +88,7 @@ class FilingAFinding(FindingsTest):
filed = self.store.issues[-1] filed = self.store.issues[-1]
self.assertEqual((code, out, filed.labels), (0, f"Filed {filed.key} in the epic ABC-12.\n", ("do-epic-release-review", "repo:api"))) self.assertEqual((code, out, filed.labels), (0, f"Filed {filed.key} in the epic ABC-12.\n", ("do-epic-release-review", "repo:api")))
code, out, _, _ = self.run_with(["ABC-12", "--file", "Review api", "--label", "do-epic-release-review"]) code, out, _, _ = self.run_with(["ABC-12", "--file", "Review api", "--label", "do-epic-release-review"])
self.assertEqual((code, out), (0, f"Filed {self.store.issues[-1].key} in the epic ABC-12. It waits until someone labels it: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n")) self.assertEqual((code, out), (0, f"Filed {self.store.issues[-1].key} in the epic ABC-12. It has no label that says where it is worked, so the next `do-epic ABC-12` picks one: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n"))
def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None: def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None:
for label in ("api", "repo:", "repo:a b"): for label in ("api", "repo:", "repo:a b"):
+6 -5
View File
@@ -35,7 +35,7 @@ DESCRIPTION = "**Max parallel chunks:** 2\n\n## Goals\nShip the import.\n\n## Au
def structured(output: object, key: str | None = "structured_output") -> subprocess.CompletedProcess[str]: 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.""" """claude's reply that holds output as its structured answer. Where key is None, output is the whole result event."""
return subprocess.CompletedProcess([], 0, json.dumps({"type": "result", key: output} if key else output), "") return subprocess.CompletedProcess([], 0, json.dumps({"type": "result", key: output} if key else output), "")
@@ -153,11 +153,12 @@ class TheCommand(DoEpicTest):
self.assertIn("the epic is not planned, so no chunk started: You've hit your limit\n", err) 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"], []) 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: def test_says_why_the_epic_is_not_planned_in_full_and_starts_the_chunks_that_may_start(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")] 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()) code, out, err = self.run_main(["ABC-12"], FakeEffects())
self.assertEqual(code, 1) self.assertEqual(code, 0, err)
self.assertIn("states `Score = ...` 0 times under ## Scoring", err) self.assertIn("the epic ABC-12 is not planned in full: the epic ABC-12's description states `Score = ...` 0 times under ## Scoring", err)
self.assertIn("started ABC-20, ABC-21 in the tmux session epic-ABC-12\n", out)
def test_stops_on_an_epic_it_cannot_read(self) -> None: def test_stops_on_an_epic_it_cannot_read(self) -> None:
self.description = Failure("Jira answered 401") self.description = Failure("Jira answered 401")
+100 -24
View File
@@ -3,6 +3,7 @@ import dataclasses
import io import io
import json import json
import pathlib import pathlib
import shutil
import subprocess import subprocess
import sys import sys
@@ -43,7 +44,8 @@ class Planning(DoEpicTest):
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked): with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
read = store.read() read = store.read()
assert not isinstance(read, Failure) assert not isinstance(read, Failure)
return planning.planned(epic, read), store, out.getvalue() issues, stopped = planning.planned(epic, read)
return issues if stopped is None else stopped, store, out.getvalue()
def labels(self, store: MemoryEpic) -> dict[str, tuple[str, ...]]: def labels(self, store: MemoryEpic) -> dict[str, tuple[str, ...]]:
return {each.key: each.labels for each in store.issues} return {each.key: each.labels for each in store.issues}
@@ -140,19 +142,62 @@ class Planning(DoEpicTest):
found, store, out = self.plan(fake) found, store, out = self.plan(fake)
self.assertEqual(found, [issue("ABC-20", "repo:web")]) self.assertEqual(found, [issue("ABC-20", "repo:web")])
self.assertIn("ABC-20, Do ABC-20: Is the importer in api or in web?\n", self.asked.getvalue()) 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.assertIn("`api` is none of those labels; the repo api's label is `repo:api`\n", self.asked.getvalue())
self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:<name>`, `do-epic-claude` or `do-epic-human`: "] * 2) self.assertEqual(fake.made("input"), ["The label that says where ABC-20 is worked, `repo:<name>`, `do-epic-claude` or `do-epic-human`, or Enter alone to leave it waiting: "] * 2)
def test_an_unclear_issue_waits_where_nobody_can_answer_and_the_next_is_planned(self) -> None: def unclear_then_claudes(self, **fake: object) -> tuple[dict[str, tuple[str, ...]], str]:
"""The labels and the output after planning ABC-20, which the rule leaves unclear, and ABC-21, which is Claude's, on a FakeEffects made with fake."""
self.issues = [issue("ABC-20"), issue("ABC-21")]
unclear = says({"pick": "unclear", "question": "Is the importer in api or in web?"}) 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()])): _, store, out = self.plan(FakeEffects(claude=[says({"parts": []}), unclear, says({"parts": []}), says({"pick": "claude"})], **fake)) # type: ignore[arg-type]
with self.subTest(on_terminal=fake.terminal): return self.labels(store), out
self.issues = [issue("ABC-20"), issue("ABC-21")]
_, store, out = self.plan(fake) def test_an_unclear_issue_waits_off_a_terminal_and_the_next_is_planned(self) -> None:
self.assertEqual(self.labels(store), {"ABC-20": (), "ABC-21": ("do-epic-claude",)}) labels, out = self.unclear_then_claudes(on_terminal=False)
self.assertNotIn("ABC-20 is labelled", out) self.assertEqual(labels, {"ABC-20": (), "ABC-21": ("do-epic-claude",)})
if not fake.terminal: self.assertNotIn("ABC-20 is labelled", out)
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) 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_unclear_issue_waits_where_the_human_answers_with_enter_alone(self) -> None:
labels, out = self.unclear_then_claudes(inputs=[" "])
self.assertEqual((labels, "ABC-20 is labelled" in out), ({"ABC-20": (), "ABC-21": ("do-epic-claude",)}, False))
def test_an_unclear_issue_waits_where_the_terminals_input_ends(self) -> None:
labels, out = self.unclear_then_claudes(inputs=[EOFError()])
self.assertEqual((labels, "ABC-20 is labelled" in out), ({"ABC-20": (), "ABC-21": ("do-epic-claude",)}, False))
def test_clones_a_labelled_repo_without_a_checkout_beside_the_origin_of_the_others(self) -> None:
configured(self, self.home / "code" / "api", home=self.home)
configured(self, self.home / "code" / "web", home=self.home)
shutil.rmtree(self.home / "code" / "web")
self.issues = [issue("ABC-18", "repo:api", done=True), issue("ABC-19", "repo:web", done=True), issue("ABC-20")]
fake = FakeEffects(git=["https://git.example/acme/api.git\n", ""], claude=[says({"parts": []}), says({"pick": "claude"})])
self.plan(fake)
origin, clone = fake.made("git")
self.assertEqual((origin, clone[-4:]), (["remote", "get-url", "origin"], ["clone", "--", "https://git.example/acme/web", str(self.home / "code" / "web")]))
def health_first(self, floor: str) -> list[str]:
"""The order of ABC-20, which moves the epic's goal by 9, and ABC-21, which moves code health by 3 in a repo that scored 7.5 and whose config ends with the line floor."""
checkout = self.home / "code" / "api"
folder = configured(self, checkout, home=self.home)
with (folder / "config.toml").open("a", encoding="utf-8") as config:
config.write(floor)
(checkout / "README.md").write_text("## Goals\n\n1. **Achieve:** Serve the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
(checkout / "docs").mkdir()
(checkout / "docs" / "comprehension-history.md").write_text("# Comprehension history\n\n## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mid A | 6 |\n| Mean | 7.5 |\n", encoding="utf-8")
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 9", "do-epic-claude"), scored("ABC-21", "code health by 3", "repo:api")]
found = self.plan(FakeEffects())[0]
assert not isinstance(found, Failure | Limited), found
return [each.key for each in found]
def test_code_health_weighs_four_times_in_a_repo_under_the_floor_its_config_sets(self) -> None:
# 4 * 3 * 0.97 is above the 9 of the epic's first goal.
self.assertEqual(self.health_first("readability-floor = 8.0\n"), ["ABC-21", "ABC-20"])
def test_code_health_weighs_once_in_a_repo_at_its_floor(self) -> None:
# 3 * 0.97 is under the 9 of the epic's first goal.
self.assertEqual(self.health_first(""), ["ABC-20", "ABC-21"])
def test_an_issue_claude_fails_on_is_named_and_the_next_is_planned(self) -> None: def test_an_issue_claude_fails_on_is_named_and_the_next_is_planned(self) -> None:
self.issues = [issue("ABC-20"), issue("ABC-21")] self.issues = [issue("ABC-20"), issue("ABC-21")]
@@ -175,7 +220,7 @@ class Planning(DoEpicTest):
assert not isinstance(found, Failure | Limited), found 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. # 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.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) self.assertIn("re-ranking the issues do-epic filed in ABC-12's backlog\n", out)
def test_ranks_an_issue_in_a_repo_by_that_repos_goals_after_the_epics(self) -> None: def test_ranks_an_issue_in_a_repo_by_that_repos_goals_after_the_epics(self) -> None:
checkout = self.home / "code" / "api" checkout = self.home / "code" / "api"
@@ -196,7 +241,7 @@ class Planning(DoEpicTest):
def test_fails_where_the_epic_states_no_formula_to_rank_two_scored_issues_by(self) -> None: 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")] 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()) 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(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 and inside backticks, such as `Score = 100 * V / (2**S + 32)`"))
self.assertEqual([each.key for each in store.issues], ["ABC-20", "ABC-21"]) 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: def test_fails_where_the_formula_names_a_score_no_issue_holds(self) -> None:
@@ -207,7 +252,7 @@ class Planning(DoEpicTest):
def test_fails_where_two_issues_to_rank_share_a_number(self) -> None: def test_fails_where_two_issues_to_rank_share_a_number(self) -> None:
self.description = RANKED 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.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")) self.assertEqual(self.plan(FakeEffects())[0], Failure("ABC-20 and XYZ-20 share a number in different Jira projects, so the issues do-epic filed in the epic ABC-12 cannot be ranked; move one of the two to the other's Jira project"))
def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None: def test_fails_where_the_description_cannot_be_read_to_rank_by(self) -> None:
self.description = Failure("Jira answered 503") self.description = Failure("Jira answered 503")
@@ -235,14 +280,45 @@ class Planning(DoEpicTest):
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), issue("ABC-21", "do-epic-claude")] 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) self.assertEqual(self.plan(FakeEffects())[0], self.issues)
def test_fails_where_the_tracker_cannot_be_read_after_a_pick(self) -> None: def planned_on(self, store: MemoryEpic, fake: FakeEffects) -> tuple[list[EpicIssue], Failure | Limited | None]:
self.issues = [issue("ABC-20")] """What planning answers for self.issues on a store that doesn't read as MemoryEpic does."""
def failing(_: object) -> subprocess.CompletedProcess[str]:
self.store.fails = "Jira answered 503"
return says({"parts": []})
config = load(self.home) config = load(self.home)
self.store = MemoryEpic("ABC-12", list(self.issues)) assert not isinstance(config, Failure), config
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] epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, fake.effects()) # type: ignore[arg-type]
with contextlib.redirect_stdout(io.StringIO()): with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(planning.planned(epic, list(self.issues)), Failure("Jira answered 503")) return planning.planned(epic, list(self.issues))
def test_a_label_it_added_counts_where_the_tracker_cannot_be_read_afterwards(self) -> None:
self.issues = [issue("ABC-20")]
found = self.planned_on(Unreadable("ABC-12", list(self.issues)), FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"})]))
self.assertEqual(found, ([issue("ABC-20", "do-epic-claude")], Failure("Jira answered 503")))
def test_a_label_and_an_order_it_wrote_count_where_the_trackers_search_lags(self) -> None:
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "epic 1 by 9"), issue("ABC-22")]
parts = says({"parts": [{"repo": "api", "change": "Add the endpoint."}, {"repo": "web", "change": "Call it."}], "comment": "Split by repo: api and web."})
found, stopped = self.planned_on(Lagging("ABC-12", list(self.issues)), FakeEffects(claude=[says({"parts": []}), says({"pick": "claude"}), parts]))
self.assertEqual(([(each.key, each.labels) for each in found], stopped), ([("ABC-21", ("do-epic-claude",)), ("ABC-20", ("do-epic-claude",)), ("ABC-22", ("split-by-repo",))], None))
def test_an_issue_without_a_pick_is_not_ranked(self) -> None:
self.description = RANKED
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude"), scored("ABC-21", "code health by 9")]
found, _, out = self.plan(FakeEffects(claude=[subprocess.CompletedProcess([], 1, "", "")]))
self.assertEqual((found, "re-ranking" in out), (self.issues, False))
class Unreadable(MemoryEpic):
"""A tracker that fails each read once an issue is labelled."""
def add_label(self, key: str, label: str) -> None | Failure:
self.fails = "Jira answered 503"
return None
class Lagging(MemoryEpic):
"""A tracker whose search shows the issues as they were before any write."""
def read(self) -> list[EpicIssue] | Failure:
return list(self.before)
def __init__(self, key: str, issues: list[EpicIssue]) -> None:
super().__init__(key, issues)
self.before = list(issues)
+1 -1
View File
@@ -299,7 +299,7 @@ class TheFirstPrompt(unittest.TestCase):
def test_the_task_names_the_checkout_and_branch_and_quotes_a_description_only_where_there_is_one(self) -> None: def test_the_task_names_the_checkout_and_branch_and_quotes_a_description_only_where_there_is_one(self) -> None:
labels = "`repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's" labels = "`repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's"
told = ( told = (
f"File a finding about one of the epic's goals in the epic, with `/b/do-epic ABC-12 --file \"<summary>\" --label <label>` and its detail on stdin. The label is {labels}; leave it out where you cannot tell, and the issue waits for the human. " f"File a finding about one of the epic's goals in the epic, with `/b/do-epic ABC-12 --file \"<summary>\" --label <label>` and its detail on stdin. The label is {labels}; leave it out where you cannot tell, and the next `do-epic` the human runs picks it. "
"Where filing fails and says the issue may exist, ask the human to look before you file it again. File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. " "Where filing fails and says the issue may exist, ask the human to look before you file it again. File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
"Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. Write the issue and the decision in Swedish, the epic's language." "Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. Write the issue and the decision in Swedish, the epic's language."
) )
+4 -4
View File
@@ -72,13 +72,13 @@ class Split_(unittest.TestCase):
def test_a_first_filing_that_fails_says_the_run_filed_no_sub_task(self) -> None: def test_a_first_filing_that_fails_says_the_run_filed_no_sub_task(self) -> None:
self.store.fails_files = True self.store.fails_files = True
self.assertEqual(self.run_split(says(TWO)), Failure(f"cannot file the sub-task for api under {self.key}: Jira answered 500; this run filed no sub-task; run split again to file the rest")) self.assertEqual(self.run_split(says(TWO)), Failure(f"cannot file the sub-task for api under {self.key}: Jira answered 500; this run filed no sub-task; run do-epic again to file the rest"))
def test_a_comment_that_fails_leaves_the_item_unmarked_and_the_next_run_files_nothing_again(self) -> None: def test_a_comment_that_fails_leaves_the_item_unmarked_and_the_next_run_files_nothing_again(self) -> None:
self.store.fails_comments = True self.store.fails_comments = True
failed = self.run_split(says(TWO), by_person=True) failed = self.run_split(says(TWO), by_person=True)
first, second = (task.key for task in self.tasks()) first, second = (task.key for task in self.tasks())
self.assertEqual(failed, Failure(f"cannot comment on {self.key}: Jira answered 500; this run filed {first}, {second}; run split again to post it")) self.assertEqual(failed, Failure(f"cannot comment on {self.key}: Jira answered 500; this run filed {first}, {second}; run do-epic again to post it"))
self.assertEqual(self.issue().labels, ("api",)) self.assertEqual(self.issue().labels, ("api",))
self.store.fails_comments = False self.store.fails_comments = False
done = self.run_split(says(TWO), by_person=True) done = self.run_split(says(TWO), by_person=True)
@@ -116,7 +116,7 @@ class Split_(unittest.TestCase):
self.store.jammed = True self.store.jammed = True
failed = self.run_split(says(TWO), by_person=True) failed = self.run_split(says(TWO), by_person=True)
first = self.tasks()[0].key first = self.tasks()[0].key
self.assertEqual(failed, Failure(f"cannot file the sub-task for web under {self.key}: Jira answered 500; this run filed {first}; run split again to file the rest")) self.assertEqual(failed, Failure(f"cannot file the sub-task for web under {self.key}: Jira answered 500; this run filed {first}; run do-epic again to file the rest"))
self.assertEqual(self.issue().labels, ("api",)) self.assertEqual(self.issue().labels, ("api",))
self.store.jammed = False self.store.jammed = False
done = self.run_split(says(TWO), by_person=True) done = self.run_split(says(TWO), by_person=True)
@@ -176,7 +176,7 @@ class Split_(unittest.TestCase):
self.store.add_label = lambda key, label: Failure("Jira answered 500") if label == SPLIT_LABEL else None # type: ignore[method-assign] self.store.add_label = lambda key, label: Failure("Jira answered 500") if label == SPLIT_LABEL else None # type: ignore[method-assign]
failed = self.run_split(says(TWO)) failed = self.run_split(says(TWO))
first, second = (task.key for task in self.tasks()) first, second = (task.key for task in self.tasks())
self.assertEqual(failed, Failure(f"cannot mark {self.key} as split: Jira answered 500; this run filed {first}, {second}; run split again to mark it")) self.assertEqual(failed, Failure(f"cannot mark {self.key} as split: Jira answered 500; this run filed {first}, {second}; run do-epic again to mark it"))
def test_passes_on_a_failed_or_limited_claude(self) -> None: def test_passes_on_a_failed_or_limited_claude(self) -> None:
self.assertEqual(self.run_split(Claude("", 1)), Failure("the repo split exited 1")) self.assertEqual(self.run_split(Claude("", 1)), Failure("the repo split exited 1"))