diff --git a/README.md b/README.md index eeaee08b..250d1d18 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `chunk_driver/` holds what the entry points share. An entry point is a tool that drives chunks through `agent_cycle`: `loop_claude` and `do_epic` are the two. They share how a cycle starts (`cycle_start.py`) and closes (`chunk_run.py`), the claim on a checkout before a chunk starts in it (`claims.py`), the prompts every worker gets (`prompts.py`), and a checkout's premises, records and saved models (`project/`). It imports neither entry point, and `repo_checks` fails any package that imports one of the two. `agent_cycle` is the layer below it, and `repo_checks` fails `agent_cycle` where it imports `chunk_driver`, tests included. - `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 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`, which takes `--blocked-by` to make the issue wait for another of the epic's and `--parent` to file it as a sub-task, so a change a repo ships as two pull requests gets an issue for each, 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. `e2e/` holds `do-epic-e2e`. +- `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. `e2e/` holds `do-epic-e2e`. - `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), finds a pull request and reads its checks, once or until they settle (`pulls.py`), and reads a pull request's review state (`reviews.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 `chunk_driver`'s premises, records and `ANSWER_DESTINATIONS`. diff --git a/bin/do_epic/backend/jira.py b/bin/do_epic/backend/jira.py index 6891e3df..e9f470de 100644 --- a/bin/do_epic/backend/jira.py +++ b/bin/do_epic/backend/jira.py @@ -74,17 +74,16 @@ class JiraEpic: if isinstance(description, Failure): return Failure(f"cannot convert the detail to a Jira description: {description.reason}") fields["description"] = description - created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, {"fields": fields | {"issuetype": kind}, "properties": properties}) + body: dict[str, typing.Any] = {"fields": fields | {"issuetype": kind}, "properties": properties} + if blocked_by: + # Linked as it is created, so no issue is left filed and unblocked. The inward issue blocks the new one. + body["update"] = {"issuelinks": [{"add": {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocked_by}}}]} + created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, body) if isinstance(created, Failure): return Failure(f"cannot file the issue under {parent}: {created.reason}; {PERHAPS_FILED.format(under=parent)}") key = created.get("key") if isinstance(created, dict) else None if not isinstance(key, str) or not ISSUE_KEY.fullmatch(key): return Failure(f"Jira answered the new issue without an issue key; {PERHAPS_FILED.format(under=parent)}") - if blocked_by: - # Jira names the two ends by the link type's sides: the inward issue blocks the outward one, which then reads "is blocked by" it. - linked = self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocked_by}, "outwardIssue": {"key": key}}) - if isinstance(linked, Failure): - return Failure(f"filed {key} under {parent}, but cannot link it as blocked by {blocked_by}: {linked.reason}; link it in Jira") return key def add_label(self, key: str, label: str) -> None | Failure: diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py index af51d7d1..a4a6b9a3 100644 --- a/bin/do_epic/backend/protocol.py +++ b/bin/do_epic/backend/protocol.py @@ -52,7 +52,7 @@ class EpicStore(typing.Protocol): """Each child issue, open or done, in the tracker's rank order, each followed by its sub-tasks in theirs.""" def file(self, parent: str, summary: str, detail: str, labels: tuple[str, ...], blocked_by: str | None = None) -> str | Failure: - """Files an open issue under parent, marked as filed by the loop, and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty. Where blocked_by names an issue, a child issue of the epic or a sub-task of one, the new issue is blocked by it; any other issue is refused before anything is filed. Where the issue is filed and cannot be linked, the Failure names its key.""" + """Files an open issue under parent, marked as filed by the loop, and answers its key: a child issue where parent is the epic, a sub-task where parent is one of its child issues. detail is markdown, and may be empty. Where blocked_by names an issue, a child issue of the epic or a sub-task of one, the new issue is blocked by it; any other issue is refused before anything is filed.""" def add_label(self, key: str, label: str) -> None | Failure: """Adds label to the epic's child issue named key, leaving its other labels as they are; adding one it already has leaves the labels as they are. A sub-task, or an issue outside the epic, is refused.""" @@ -95,7 +95,7 @@ def no_parent(epic_key: str, parent: str) -> Failure: def no_blocker(epic_key: str, blocker: str) -> Failure: """What every backend says when asked to file an issue blocked by blocker, which is neither a child issue of the epic nor a sub-task of one.""" - return Failure(f"{blocker} is neither a child issue of the epic {epic_key} nor a sub-task of one, so nothing can be filed blocked by it") + return Failure(f"{blocker} is neither a child issue of the epic {epic_key} nor a sub-task of one, so it cannot block a new issue") def no_child(epic_key: str, key: str, done_to_it: str) -> Failure: diff --git a/bin/do_epic/backend/test_jira.py b/bin/do_epic/backend/test_jira.py index 6f2384f9..5d930326 100644 --- a/bin/do_epic/backend/test_jira.py +++ b/bin/do_epic/backend/test_jira.py @@ -21,7 +21,6 @@ EPIC_URL = f"{SITE}/rest/api/3/issue/ABC-12?fields=summary" ISSUE_TYPES = f"{SITE}/rest/api/3/issue/createmeta/ABC/issuetypes" SEARCH = f"{SITE}/rest/api/3/search/jql" ISSUES = f"{SITE}/rest/api/3/issue" -LINKS = f"{SITE}/rest/api/3/issueLink" RANK = f"{SITE}/rest/agile/1.0/issue/rank" TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}} DONE = {"name": "Done", "statusCategory": {"key": "done"}} @@ -92,11 +91,6 @@ class FakeJira: return self.created(body) if method == "PUT" and url == RANK: return self.ranked(body) - if method == "POST" and url == LINKS: - assert isinstance(body, dict) and body["type"] == {"name": "Blocks"}, body - links = next(issue for issue in self.issues if issue["key"] == body["outwardIssue"]["key"])["fields"]["issuelinks"] # type: ignore[index] - links.append({"id": str(len(links) + 1), "type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": body["inwardIssue"]}) # type: ignore[index] - return None if method == "POST" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}/comment"), None)): assert isinstance(body, dict) self.comments.setdefault(str(held["key"]), []).append(body["body"]) @@ -126,7 +120,9 @@ class FakeJira: if fields["project"] != {"key": "ABC"} or kind is None or fields["issuetype"] != kind: return Failure("Jira answered 400: the project, parent or issue type is not valid") key = f"ABC-{len(self.issues) + 100}" - self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": parent}, "issuelinks": []}, "properties": {entry["key"]: entry["value"] for entry in body["properties"]}}) + # The links Jira makes as it creates the issue: the inward issue blocks the new one, which then reads "is blocked by" it. + links = [{"id": "1", "type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": add["add"]["inwardIssue"]} for add in body.get("update", {}).get("issuelinks", []) if add["add"]["type"] == {"name": "Blocks"}] + self.issues.append({"key": key, "fields": {"summary": fields["summary"], "description": fields.get("description"), "labels": fields["labels"], "assignee": None, "status": TO_DO, "parent": {"key": parent}, "issuelinks": links}, "properties": {entry["key"]: entry["value"] for entry in body["properties"]}}) return {"id": "1", "key": key} def ranked(self, body: object) -> object: @@ -310,14 +306,6 @@ class Jira(Case): self.jira.answers[("POST", ISSUES)] = answer self.assertEqual(self.new_store().file("ABC-12", "Count the runs.", "", ()), Failure(f"{reason}; unless Jira refused the request, the issue may exist: look under ABC-12 before filing it again")) - def test_a_link_jira_refuses_leaves_the_issue_filed_and_names_its_key(self) -> None: - store = self.new_store() - first = store.file("ABC-12", "Pin the behaviour.", "", ()) - assert isinstance(first, str) - self.jira.answers[("POST", LINKS)] = Failure("Jira answered 403") - self.assertEqual(store.file("ABC-12", "Change the behaviour.", "", (), first), Failure(f"filed ABC-101 under ABC-12, but cannot link it as blocked by {first}: Jira answered 403; link it in Jira")) - self.assertEqual([issue["key"] for issue in self.jira.issues], [first, "ABC-101"]) - def test_a_detail_the_codec_refuses_leaves_the_epic_as_it_was(self) -> None: store = JiraEpic(EPIC, self.env_file, self.jira, to_markdown, lambda markdown: Failure("adf-codec refused it")) self.assertEqual(store.file("ABC-12", "Count the runs.", "Why.", ()), Failure("cannot convert the detail to a Jira description: adf-codec refused it")) diff --git a/bin/do_epic/chunk_prompt.py b/bin/do_epic/chunk_prompt.py index d5d377e2..8e46fc25 100644 --- a/bin/do_epic/chunk_prompt.py +++ b/bin/do_epic/chunk_prompt.py @@ -30,7 +30,7 @@ def task(issue: EpicIssue, epic: str, checkout: str | None, launcher: pathlib.Pa """The task of the chunk that works issue, of the epic with the key epic: in checkout, or without a repo where it is None. launcher is the do-epic that runs the chunk, language the one the epic's Jira text is in, and config the project config of the repo's checkout, None without a repo.""" shipped = shipping(config) if config else "" where = f"in the checkout {checkout}, on the branch {issue.key}" if checkout else "which changes no repo: work in the folder you start in" - return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. {" ".join(filter(None, [findings.instructions(epic, launcher, language), shipped]))} Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "") + return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. {" ".join(filter(None, [findings.instructions(epic, launcher, language, issue), shipped]))} Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "") CODE_HEALTH = '~/.claude/CLAUDE.md → "Shared goal"' diff --git a/bin/do_epic/findings.py b/bin/do_epic/findings.py index 764bf33d..2fa3c5e6 100644 --- a/bin/do_epic/findings.py +++ b/bin/do_epic/findings.py @@ -9,7 +9,7 @@ import typing from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL, of_label, REPO_PREFIX, REVIEW_LABEL from do_epic.epic_record import EpicRecord -from do_epic.backend.protocol import EpicStore +from do_epic.backend.protocol import EpicIssue, EpicStore from failure import Failure from text_files.markdown_text import listed from text_files.piped_text import piped @@ -27,23 +27,29 @@ DECISIONS_LOCK = "decisions.lock" USAGE = f"""do-epic {FILE} [{LABEL}