From 49fe132be2763b2b316cd03f8615bf4e75377173 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 18:51:50 +0100 Subject: [PATCH 1/9] Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed --- bin/do_epic/backend/contract.py | 9 ++++ bin/do_epic/backend/fake.py | 12 ++++- bin/do_epic/backend/jira.py | 9 +++- bin/do_epic/backend/protocol.py | 3 ++ bin/do_epic/backend/test_jira.py | 26 ++++++++++ bin/do_epic/ranking.py | 30 +++++++++++ bin/do_epic/test_ranking.py | 89 +++++++++++++++++++++++++++++++- bin/plan_store/jira_epic.py | 21 ++++---- 8 files changed, 186 insertions(+), 13 deletions(-) diff --git a/bin/do_epic/backend/contract.py b/bin/do_epic/backend/contract.py index c865bb0f..365f2641 100644 --- a/bin/do_epic/backend/contract.py +++ b/bin/do_epic/backend/contract.py @@ -150,3 +150,12 @@ class EpicStoreContract: task = self.filed(store, ours, "Count them in the api.") read = {issue.key: issue for issue in self.issues(store)} self.assertEqual([read[key].by_loop for key in (ours, theirs, task)], [True, False, True]) + + def test_ranks_a_child_issue_just_before_or_just_after_another_and_its_sub_tasks_follow_it(self) -> None: + store = self.new_store() + first, second, third = (self.filed(store, store.epic_key, f"Item {n}.") for n in range(3)) + task = self.filed(store, third, "A task.") + self.assertEqual(store.rank(third, first), None) + self.assertEqual([issue.key for issue in self.issues(store)], [third, task, first, second]) + self.assertEqual(store.rank(third, second, after=True), None) + self.assertEqual([issue.key for issue in self.issues(store)], [first, second, third, task]) diff --git a/bin/do_epic/backend/fake.py b/bin/do_epic/backend/fake.py index 217ef991..8319ad55 100644 --- a/bin/do_epic/backend/fake.py +++ b/bin/do_epic/backend/fake.py @@ -7,7 +7,7 @@ from failure import Failure @dataclasses.dataclass class MemoryEpic: - """An epic whose issues rank in the order filed. Where fails is set, every read and filing fails with it as the reason.""" + """An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call fails with it as the reason.""" epic_key: str issues: list[EpicIssue] = dataclasses.field(default_factory=list) fails: str | None = None @@ -39,6 +39,16 @@ class MemoryEpic: self.change(key, labels=tuple(sorted({*child.labels, label}))) return None + def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + if self.fails: + return Failure(self.fails) + children = {issue.key: issue for issue in self.issues if issue.parent == self.epic_key} + if stray := next((each for each in (key, other) if each not in children), None): + return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so it cannot be ranked") + self.issues.remove(children[key]) + self.issues.insert(self.issues.index(children[other]) + after, children[key]) + return None + def change(self, key: str, **fields: object) -> None: """Changes the issue named key as a person would in the tracker, such as assignee="Ada Lovelace".""" self.issues = [dataclasses.replace(issue, **fields) if issue.key == key else issue for issue in self.issues] # type: ignore[arg-type] diff --git a/bin/do_epic/backend/jira.py b/bin/do_epic/backend/jira.py index d31f570b..2afa3730 100644 --- a/bin/do_epic/backend/jira.py +++ b/bin/do_epic/backend/jira.py @@ -5,7 +5,7 @@ import typing from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused from atlassian.client import basic_auth, Http, jira_json, ToAdf, ToMarkdown -from plan_store.jira_epic import blocked_by_links, FILED_BY, ISSUE_KEY, ISSUE_TYPE, project_of, PROPERTY, scores, searched +from plan_store.jira_epic import blocked_by_links, FILED_BY, ISSUE_KEY, ISSUE_TYPE, project_of, PROPERTY, rank_refusal, scores, searched from project_config.settings import Epic from do_epic.backend.protocol import EpicIssue, no_child, no_parent, unfit, unfit_label from failure import Failure @@ -92,6 +92,13 @@ class JiraEpic: edited = self.http("PUT", f"{self.epic.site}/rest/api/3/issue/{key}", authorization, {"update": {"labels": [{"add": label}]}}) return Failure(f"cannot label {key}: {edited.reason}") if isinstance(edited, Failure) else None + def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + authorization = basic_auth(self.env_file) + if isinstance(authorization, Failure): + return authorization + refused = rank_refusal(self.epic.site, key, other, after, authorization, self.http) + return Failure(refused) if refused else None + def not_a_parent(self, parent: str, authorization: str) -> Failure | None: """Why nothing can be filed under parent; None where it is the epic or one of its child issues.""" if parent == self.epic_key: diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py index 3da13e8e..48787c47 100644 --- a/bin/do_epic/backend/protocol.py +++ b/bin/do_epic/backend/protocol.py @@ -57,6 +57,9 @@ class EpicStore(typing.Protocol): 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.""" + def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + """Ranks the child issue named key just before the child issue named other, or just after it where after is True; its sub-tasks follow it. Both must be child issues of the epic, as read answers them: a backend may not check, and Jira ranks any issue it is given.""" + def unfit(summary: str, labels: tuple[str, ...]) -> Failure | None: """Why no tracker can file an issue with this summary and these labels; None where a tracker can file it.""" diff --git a/bin/do_epic/backend/test_jira.py b/bin/do_epic/backend/test_jira.py index 015d5514..0337d938 100644 --- a/bin/do_epic/backend/test_jira.py +++ b/bin/do_epic/backend/test_jira.py @@ -23,6 +23,7 @@ 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" +RANK = f"{SITE}/rest/agile/1.0/issue/rank" TO_DO = {"name": "To Do", "statusCategory": {"key": "new"}} TYPES = {"issueTypes": [{"id": "10001", "name": "Task", "subtask": False}, {"id": "10003", "name": "Subtask", "subtask": True}]} @@ -59,6 +60,8 @@ class FakeJira: return {"key": held["key"], "fields": {"parent": held["fields"]["parent"]}} # type: ignore[index] if method == "POST" and url == ISSUES: return self.created(body) + if method == "PUT" and url == RANK: + return self.ranked(body) if method == "PUT" and (held := next((issue for issue in self.issues if url == f"{ISSUES}/{issue['key']}"), None)): assert isinstance(body, dict) added = [change["add"] for change in body["update"]["labels"]] @@ -87,6 +90,15 @@ class FakeJira: 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"]}}) return {"id": "1", "key": key} + def ranked(self, body: object) -> object: + """Moves the one issue named just before or just after another, and answers no body, as Jira does for a rank it made.""" + assert isinstance(body, dict) + [key], other = body["issues"], body.get("rankBeforeIssue") or body["rankAfterIssue"] + moved = next(issue for issue in self.issues if issue["key"] == key) + self.issues.remove(moved) + self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == other) + ("rankAfterIssue" in body), moved) + return None + def change(self, key: str, **fields: object) -> None: next(issue for issue in self.issues if issue["key"] == key)["fields"].update(fields) # type: ignore[union-attr] @@ -231,6 +243,20 @@ class Jira(Case): store = JiraEpic(Epic(SITE, "ABC-99"), self.env_file, self.jira, to_markdown, to_adf) self.assertEqual(store.read(), Failure(f"cannot read the epic ABC-99: Jira answered 404 for GET {SITE}/rest/api/3/issue/ABC-99?fields=summary")) + def test_a_rank_jira_refuses_fails_with_its_reason_and_ranks_nothing(self) -> None: + store = self.new_store() + first, second = (store.file("ABC-12", f"Item {n}.", "", ()) for n in range(2)) + for answer, reason in ( + (Failure("Jira answered 403"), "Jira answered 403"), + ({"entries": [{"issueKey": second, "status": 400, "errors": ["Rank is not configured"]}]}, "Rank is not configured"), + ): + with self.subTest(answer=answer): + self.jira.answers[("PUT", RANK)] = answer + self.assertEqual(store.rank(str(second), str(first)), Failure(reason)) + read = store.read() + assert isinstance(read, list), read + self.assertEqual([issue.key for issue in read], [first, second]) + if __name__ == "__main__": unittest.main() diff --git a/bin/do_epic/ranking.py b/bin/do_epic/ranking.py index 6625868e..438cc9ab 100644 --- a/bin/do_epic/ranking.py +++ b/bin/do_epic/ranking.py @@ -7,6 +7,7 @@ import ast import dataclasses import decimal +from do_epic.backend.protocol import EpicStore from plan.blockers import blockers_first from plan.todo_table import CODE_HEALTH, EPIC_GOAL, Item, REPO_GOAL, SHAPE from failure import Failure @@ -59,6 +60,35 @@ def ranked(items: list[EpicItem], formula: str, epic_goals: str, repos: dict[str return blockers_first(scored) +def reranked(store: EpicStore, order: list[str]) -> None | Failure: + """Ranks the epic's child issues named in order, each one the loop filed, so the tracker's backlog lists them in order. Each other child issue, such as one a person filed, keeps its slot; the slots of the named issues take them in order's order. A sub-task holds no slot and follows its parent. + + The walk goes from the backlog's end: an issue not just before the one that follows it in the target ranks just before that one, so only the loop's issues move. The target's last issue, where it isn't already last, ranks just after the issue that is. A rank the tracker refuses stops the walk, which fails naming it, since a wrongly ranked team backlog takes hours to restore; the ranks made before it stay.""" + read = store.read() + if isinstance(read, Failure): + return read + children = [issue for issue in read if issue.parent == store.epic_key] + if stray := next((key for key in order if key not in {issue.key for issue in children if issue.by_loop}), None): + return Failure(f"{stray} is not one of the child issues of the epic {store.epic_key} that the loop filed, so the backlog was not re-ranked") + if twice := next((key for key in order if order.count(key) > 1), None): + return Failure(f"the order names {twice} twice, so the backlog was not re-ranked") + now = [issue.key for issue in children] + slots = iter(order) + target = [next(slots) if key in order else key for key in now] + for place in reversed(range(len(target))): + key = target[place] + at = now.index(key) + # The slices are empty past the end, so the last issue already in place is skipped too. + if key not in order or now[at + 1:at + 2] == target[place + 1:place + 2]: + continue + other, after = (now[-1], True) if place == len(target) - 1 else (target[place + 1], False) + if refused := store.rank(key, other, after): + return Failure(f"cannot rank {key} just {'after' if after else 'before'} {other}: {refused.reason}; the re-rank stopped there, so rank the loop's issues in {store.epic_key}'s backlog by hand as {', '.join(order)}") + now.remove(key) + now.insert(now.index(other) + after, key) + return None + + def chain_scoring(formula: ast.Expression, epic_goals: str, repo: str | None, own: RepoRanking | None) -> ranking.Scoring | Failure: """How an item in repo scores: the chain's goals, and what each achieve goal weighs. The bar is 0, since a bar decides what is filed, and the order holds every item that was. diff --git a/bin/do_epic/test_ranking.py b/bin/do_epic/test_ranking.py index f6ab1c08..10c17e91 100644 --- a/bin/do_epic/test_ranking.py +++ b/bin/do_epic/test_ranking.py @@ -6,7 +6,8 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from do_epic.ranking import chain, EpicItem, ranked, RepoRanking +from do_epic.backend.fake import MemoryEpic +from do_epic.ranking import chain, EpicItem, ranked, reranked, RepoRanking from failure import Failure from plan.todo_table import Item, parse_moves @@ -155,5 +156,91 @@ class RankedTest(unittest.TestCase): self.assertIsInstance(order([item(1, "epic 1 by 9")], {"billing-api": VOIDED}, "V +"), Failure) +class Recording(MemoryEpic): + """A MemoryEpic that keeps each rank asked of it, and refuses the one to rank the issue named in refused.""" + refused: str | None = None + asked: list[tuple[str, str, bool]] + + def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + self.asked.append((key, other, after)) + return Failure("Jira answered 403") if key == self.refused else super().rank(key, other, after) + + +def epic(*people: int, issues: int = 4) -> Recording: + """An epic of child issues ABC-100 onwards, the loop's apart from those whose places are in people.""" + store = Recording("ABC-12") + store.asked = [] + for place in range(issues): + store.file("ABC-12", f"Item {place}.", "", ()) + if place in people: + store.change(f"ABC-{100 + place}", by_loop=False) + return store + + +def keys(store: MemoryEpic) -> list[str]: + read = store.read() + assert isinstance(read, list), read + return [issue.key for issue in read] + + +class RerankedTest(unittest.TestCase): + def test_the_loops_issues_take_their_slots_in_the_order_given_and_a_persons_keep_theirs(self) -> None: + store = epic(1) + self.assertEqual(reranked(store, ["ABC-103", "ABC-100", "ABC-102"]), None) + self.assertEqual(keys(store), ["ABC-103", "ABC-101", "ABC-100", "ABC-102"]) + + def test_the_last_slot_takes_its_issue_where_a_persons_issue_comes_before_it(self) -> None: + store = epic(0, issues=3) + self.assertEqual(reranked(store, ["ABC-102", "ABC-101"]), None) + self.assertEqual(keys(store), ["ABC-100", "ABC-102", "ABC-101"]) + + def test_an_order_the_backlog_already_reads_in_ranks_nothing(self) -> None: + store = epic(1) + self.assertEqual(reranked(store, ["ABC-100", "ABC-102", "ABC-103"]), None) + self.assertEqual(store.asked, []) + + def test_ranks_only_the_issues_out_of_place(self) -> None: + store = epic(issues=5) + self.assertEqual(reranked(store, ["ABC-100", "ABC-101", "ABC-102", "ABC-104", "ABC-103"]), None) + self.assertEqual(store.asked, [("ABC-103", "ABC-104", True)]) + + def test_an_issue_the_order_doesnt_name_keeps_its_slot(self) -> None: + store = epic() + store.change("ABC-101", status="Done", done=True) + self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-100"]), None) + self.assertEqual(keys(store), ["ABC-103", "ABC-101", "ABC-102", "ABC-100"]) + + def test_sub_tasks_hold_no_slot_and_follow_their_parent(self) -> None: + store = epic(issues=2) + task = store.file("ABC-100", "A task.", "", ()) + self.assertEqual(reranked(store, ["ABC-101", "ABC-100"]), None) + self.assertEqual(keys(store), ["ABC-101", "ABC-100", task]) + + def test_refuses_an_order_naming_a_persons_issue_a_sub_task_an_issue_outside_the_epic_or_one_twice(self) -> None: + store = epic(1) + task = store.file("ABC-100", "A task.", "", ()) + for order, reason in ( + (["ABC-101", "ABC-100"], "ABC-101 is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"), + ([task, "ABC-100"], f"{task} is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"), + (["ZZZ-1"], "ZZZ-1 is not one of the child issues of the epic ABC-12 that the loop filed, so the backlog was not re-ranked"), + (["ABC-100", "ABC-102", "ABC-100"], "the order names ABC-100 twice, so the backlog was not re-ranked"), + ): + with self.subTest(order=order): + self.assertEqual(reranked(store, order), Failure(reason)) + self.assertEqual(store.asked, []) + + def test_a_rank_the_tracker_refuses_stops_the_walk_and_names_the_order_to_finish_by_hand(self) -> None: + store = epic() + store.refused = "ABC-101" + self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100")) + self.assertEqual(store.asked, [("ABC-100", "ABC-103", True), ("ABC-101", "ABC-100", False)]) + + def test_a_read_that_fails_ranks_nothing(self) -> None: + store = epic() + store.fails = "Jira is down" + self.assertEqual(reranked(store, ["ABC-101"]), Failure("Jira is down")) + self.assertEqual(store.asked, []) + + if __name__ == "__main__": unittest.main() diff --git a/bin/plan_store/jira_epic.py b/bin/plan_store/jira_epic.py index 2bf47644..7663b99c 100644 --- a/bin/plan_store/jira_epic.py +++ b/bin/plan_store/jira_epic.py @@ -156,7 +156,7 @@ class JiraPlan: notes.append(f"filed {key}, but cannot link it as blocked by {blocker}: {linked.reason}; link it in Jira") if isinstance(before, Failure): notes.append(f"filed {key}, but cannot rank it: {before.reason}; rank it in Jira") - elif before is not None and (refused := self.rank_refusal(key, before, authorization)): + elif before is not None and (refused := rank_refusal(self.epic.site, key, before, False, authorization, self.http)): notes.append(f"filed {key}, but cannot rank it before {before}: {refused}; rank it in Jira") return tuple(notes) @@ -178,15 +178,6 @@ class JiraPlan: notes.append(f"edited {issue.key}, but cannot delete the link that makes it blocked by {link.blocker}: {deleted.reason}; delete it in Jira") return tuple(notes) - def rank_refusal(self, key: str, before: str, authorization: str) -> str | None: - """Ranks the issue named key just before the issue named before; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors.""" - answer = self.http("PUT", f"{self.epic.site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankBeforeIssue": before}) - if isinstance(answer, Failure): - return answer.reason - entries = answer.get("entries") if isinstance(answer, dict) else None - refused = [entry for entry in entries if isinstance(entry, dict) and entry.get("status") != 200] if isinstance(entries, list) else [] - return "; ".join(str(error) for entry in refused for error in entry.get("errors") or [f"Jira answered {entry.get('status')}"]) or None - def fix_version(self, release: str, authorization: str) -> str | Failure: """The name of the Jira project's Fix Version for release, which a project may spell with a leading v, as `earliest_release` reads it.""" project = project_of(self.epic.key) @@ -451,6 +442,16 @@ def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failu return searched(epic.site, f"{epic.key}'s children", f'parent = "{epic.key}" AND statusCategory != Done ORDER BY Rank ASC', {"fields": ["summary", "description", "fixVersions", "issuelinks"], "properties": [PROPERTY]}, authorization, http) +def rank_refusal(site: str, key: str, other: str, after: bool, authorization: str, http: Http) -> str | None: + """Ranks the issue named key just before the issue named other, or just after it where after is True; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors.""" + answer = http("PUT", f"{site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankAfterIssue" if after else "rankBeforeIssue": other}) + if isinstance(answer, Failure): + return answer.reason + entries = answer.get("entries") if isinstance(answer, dict) else None + refused = [entry for entry in entries if isinstance(entry, dict) and entry.get("status") != 200] if isinstance(entries, list) else [] + return "; ".join(str(error) for entry in refused for error in entry.get("errors") or [f"Jira answered {entry.get('status')}"]) or None + + def searched(site: str, what: str, jql: str, asked: dict[str, object], authorization: str, http: Http) -> list[object] | Failure: """Every issue a JQL search on site finds, page by page. The dict asked holds the request's `fields` and `properties` lists. The text what names the issues sought, in the Failure of a search that doesn't end.""" body: dict[str, object] = {"jql": jql, "maxResults": PAGE} | asked -- 2.52.0 From 57b48ae574759d8f41b0c5df4513d837717ecb9d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 18:52:03 +0100 Subject: [PATCH 2/9] 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 97294917..61f81f89 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -2769,3 +2769,37 @@ Read most (opens and searches): - `principles/technical-principles.md` 2 - `README.md` 1 - `agents/stability-reviewer.md` 1 + +## Reading cost, chunk 2d5517bc28c1, finished 2026-11-18T17:36:08Z + +68632 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/plan_store/test_stores.py` 4 +- `bin/adf_codec/test_adf_codec.py` 3 +- `bin/loop_claude/test_black_box.py` 3 +- `bin/plan/test_touches.py` 3 +- `bin/routing_figures/test_routing_figures.py` 3 +- `bin/run_heavy/test_run_heavy.py` 3 +- `README.md` 2 +- `bin/loop_claude/test_loop_claude.py` 2 +- `bin/run_tests/test_run_tests.py` 2 +- `bin/test_env.py` 2 + +## Reading cost, chunk b4f565043ef1, finished 2026-11-18T17:47:21Z + +97239 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/plan_store/jira_epic.py` 6 +- `bin/do_epic/backend/jira.py` 4 +- `bin/do_epic/backend/test_jira.py` 3 +- `README.md` 2 +- `bin/do_epic/backend/test_fake.py` 2 +- `bin/plan/todo_table.py` 2 +- `docs/decisions.md` 2 +- `bin/do_epic/backend/contract.py` 1 +- `bin/do_epic/backend/fake.py` 1 +- `bin/do_epic/backend/protocol.py` 1 -- 2.52.0 From 676b909f15e1b076c922781472b18ad4642c8839 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 19:00:05 +0100 Subject: [PATCH 3/9] Sort the imports of the re-rank and its tests --- bin/do_epic/ranking.py | 2 +- bin/do_epic/test_ranking.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/do_epic/ranking.py b/bin/do_epic/ranking.py index 438cc9ab..488d9d54 100644 --- a/bin/do_epic/ranking.py +++ b/bin/do_epic/ranking.py @@ -7,9 +7,9 @@ import ast import dataclasses import decimal -from do_epic.backend.protocol import EpicStore from plan.blockers import blockers_first from plan.todo_table import CODE_HEALTH, EPIC_GOAL, Item, REPO_GOAL, SHAPE +from do_epic.backend.protocol import EpicStore from failure import Failure from plan.goals_file import GOAL_STEP, goal_weights, Mark, numbered, ranked_goals from review_rules.comprehension_history import latest_overall diff --git a/bin/do_epic/test_ranking.py b/bin/do_epic/test_ranking.py index 10c17e91..d4e4a414 100644 --- a/bin/do_epic/test_ranking.py +++ b/bin/do_epic/test_ranking.py @@ -6,10 +6,10 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from do_epic.backend.fake import MemoryEpic -from do_epic.ranking import chain, EpicItem, ranked, reranked, RepoRanking +from do_epic.ranking import chain, EpicItem, ranked, RepoRanking, reranked from failure import Failure from plan.todo_table import Item, parse_moves +from do_epic.backend.fake import MemoryEpic EPIC_GOALS = "1. **Achieve:** Ship invoices.\n2. **Achieve:** Cut support mail.\n3. **Maintain:** Leak no customer data.\n" VOIDED = RepoRanking("## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** Fast builds.\n", "", "", decimal.Decimal("7.0")) -- 2.52.0 From b1e46d64fa58c96abe933e165fbbef90db2cebf7 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 19:09:45 +0100 Subject: [PATCH 4/9] =?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=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 7bd192735a9ac9f6c333e156bd2138bddfca611d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 19:37:47 +0100 Subject: [PATCH 5/9] Test the fake's rank refusals and a refused rank after the last issue --- bin/do_epic/backend/test_fake.py | 11 +++++++++-- bin/do_epic/test_ranking.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/do_epic/backend/test_fake.py b/bin/do_epic/backend/test_fake.py index 24db7161..0d551f03 100644 --- a/bin/do_epic/backend/test_fake.py +++ b/bin/do_epic/backend/test_fake.py @@ -35,9 +35,16 @@ class MemoryEpicContract(EpicStoreContract, unittest.TestCase): class Failing(unittest.TestCase): - def test_every_read_and_filing_fails_with_the_reason_given(self) -> None: + def test_every_read_filing_and_rank_fails_with_the_reason_given(self) -> None: store = MemoryEpic("ABC-12", fails="Jira is down") - self.assertEqual((store.read(), store.file("ABC-12", "Count the runs.", "", ())), (Failure("Jira is down"), Failure("Jira is down"))) + self.assertEqual((store.read(), store.file("ABC-12", "Count the runs.", "", ()), store.rank("ABC-100", "ABC-101")), (Failure("Jira is down"),) * 3) + + +class Ranking(unittest.TestCase): + def test_refuses_to_rank_beside_an_issue_that_isnt_a_child_of_the_epic(self) -> None: + store = MemoryEpic("ABC-12") + child = store.file("ABC-12", "Count the runs.", "", ()) + self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be ranked")) if __name__ == "__main__": diff --git a/bin/do_epic/test_ranking.py b/bin/do_epic/test_ranking.py index d4e4a414..9e19dce5 100644 --- a/bin/do_epic/test_ranking.py +++ b/bin/do_epic/test_ranking.py @@ -235,6 +235,11 @@ class RerankedTest(unittest.TestCase): self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100")) self.assertEqual(store.asked, [("ABC-100", "ABC-103", True), ("ABC-101", "ABC-100", False)]) + def test_a_refused_rank_after_the_last_issue_names_it(self) -> None: + store = epic() + store.refused = "ABC-100" + self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-100 just after ABC-103: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100")) + def test_a_read_that_fails_ranks_nothing(self) -> None: store = epic() store.fails = "Jira is down" -- 2.52.0 From ddce0f2cb0bdea6fab3662ef6761433b33074cd5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 19:56:29 +0100 Subject: [PATCH 6/9] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20split=20the?= =?UTF-8?q?=20re-rank=20into=20the=20pure=20rank=5Fmoves,=20rank=20only=20?= =?UTF-8?q?just=20before,=20as=20the=20item=20says,=20and=20name=20ranking?= =?UTF-8?q?=20in=20the=20README=20and=20the=20protocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- bin/do_epic/backend/contract.py | 6 ++-- bin/do_epic/backend/fake.py | 10 +++--- bin/do_epic/backend/jira.py | 4 +-- bin/do_epic/backend/protocol.py | 6 ++-- bin/do_epic/backend/test_fake.py | 2 +- bin/do_epic/backend/test_jira.py | 6 ++-- bin/do_epic/ranking.py | 55 +++++++++++++++++++++----------- bin/do_epic/test_ranking.py | 51 +++++++++++++++++++---------- bin/plan_store/jira_epic.py | 8 ++--- 10 files changed, 93 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index c23cfa32..551f4a6a 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,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/` will hold the tool that drives one Jira epic. So far `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 and language 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. `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. `backend/` reads and files the epic's issues and adds those labels. +- `do_epic/` will hold the tool that drives one Jira epic. So far `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 and language 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. `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 and adds those labels. - `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 waits for its checks (`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/backend/contract.py b/bin/do_epic/backend/contract.py index 365f2641..fc793403 100644 --- a/bin/do_epic/backend/contract.py +++ b/bin/do_epic/backend/contract.py @@ -151,11 +151,11 @@ class EpicStoreContract: read = {issue.key: issue for issue in self.issues(store)} self.assertEqual([read[key].by_loop for key in (ours, theirs, task)], [True, False, True]) - def test_ranks_a_child_issue_just_before_or_just_after_another_and_its_sub_tasks_follow_it(self) -> None: + def test_ranks_a_child_issue_just_before_another_and_its_sub_tasks_follow_it(self) -> None: store = self.new_store() first, second, third = (self.filed(store, store.epic_key, f"Item {n}.") for n in range(3)) task = self.filed(store, third, "A task.") self.assertEqual(store.rank(third, first), None) self.assertEqual([issue.key for issue in self.issues(store)], [third, task, first, second]) - self.assertEqual(store.rank(third, second, after=True), None) - self.assertEqual([issue.key for issue in self.issues(store)], [first, second, third, task]) + self.assertEqual(store.rank(first, third), None) + self.assertEqual([issue.key for issue in self.issues(store)], [first, third, task, second]) diff --git a/bin/do_epic/backend/fake.py b/bin/do_epic/backend/fake.py index 8319ad55..f5f582e5 100644 --- a/bin/do_epic/backend/fake.py +++ b/bin/do_epic/backend/fake.py @@ -7,7 +7,7 @@ from failure import Failure @dataclasses.dataclass class MemoryEpic: - """An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call fails with it as the reason.""" + """An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call but change fails with it as the reason.""" epic_key: str issues: list[EpicIssue] = dataclasses.field(default_factory=list) fails: str | None = None @@ -39,14 +39,14 @@ class MemoryEpic: self.change(key, labels=tuple(sorted({*child.labels, label}))) return None - def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + def rank(self, key: str, before: str) -> None | Failure: if self.fails: return Failure(self.fails) children = {issue.key: issue for issue in self.issues if issue.parent == self.epic_key} - if stray := next((each for each in (key, other) if each not in children), None): - return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so it cannot be ranked") + if stray := next((each for each in (key, before) if each not in children), None): + return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so {key} is not ranked") self.issues.remove(children[key]) - self.issues.insert(self.issues.index(children[other]) + after, children[key]) + self.issues.insert(self.issues.index(children[before]), children[key]) return None def change(self, key: str, **fields: object) -> None: diff --git a/bin/do_epic/backend/jira.py b/bin/do_epic/backend/jira.py index 2afa3730..7bd7673b 100644 --- a/bin/do_epic/backend/jira.py +++ b/bin/do_epic/backend/jira.py @@ -92,11 +92,11 @@ class JiraEpic: edited = self.http("PUT", f"{self.epic.site}/rest/api/3/issue/{key}", authorization, {"update": {"labels": [{"add": label}]}}) return Failure(f"cannot label {key}: {edited.reason}") if isinstance(edited, Failure) else None - def rank(self, key: str, other: str, after: bool = False) -> None | Failure: + def rank(self, key: str, before: str) -> None | Failure: authorization = basic_auth(self.env_file) if isinstance(authorization, Failure): return authorization - refused = rank_refusal(self.epic.site, key, other, after, authorization, self.http) + refused = rank_refusal(self.epic.site, key, before, authorization, self.http) return Failure(refused) if refused else None def not_a_parent(self, parent: str, authorization: str) -> Failure | None: diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py index 48787c47..d6a9d4d1 100644 --- a/bin/do_epic/backend/protocol.py +++ b/bin/do_epic/backend/protocol.py @@ -1,4 +1,4 @@ -"""What every backend of an epic's plan reads, files and labels: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes. +"""What every backend of an epic's plan reads, files, labels and ranks: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes. EpicStore is not plan_store's PlanStore. A PlanStore item names a release, but an epic item has none (`docs/decisions.md` → `do-epic: drives one Jira epic …`), and it may be a sub-task.""" import dataclasses @@ -57,8 +57,8 @@ class EpicStore(typing.Protocol): 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.""" - def rank(self, key: str, other: str, after: bool = False) -> None | Failure: - """Ranks the child issue named key just before the child issue named other, or just after it where after is True; its sub-tasks follow it. Both must be child issues of the epic, as read answers them: a backend may not check, and Jira ranks any issue it is given.""" + def rank(self, key: str, before: str) -> None | Failure: + """Ranks the child issue named key just before the child issue named before. The sub-tasks of key follow key. Pass only keys of the epic's child issues, as read answers them: some backends don't check, and Jira ranks any issue it is given.""" def unfit(summary: str, labels: tuple[str, ...]) -> Failure | None: diff --git a/bin/do_epic/backend/test_fake.py b/bin/do_epic/backend/test_fake.py index 0d551f03..11621fda 100644 --- a/bin/do_epic/backend/test_fake.py +++ b/bin/do_epic/backend/test_fake.py @@ -44,7 +44,7 @@ class Ranking(unittest.TestCase): def test_refuses_to_rank_beside_an_issue_that_isnt_a_child_of_the_epic(self) -> None: store = MemoryEpic("ABC-12") child = store.file("ABC-12", "Count the runs.", "", ()) - self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be ranked")) + self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure(f"ZZZ-1 is not one of the child issues of the epic ABC-12, so {child} is not ranked")) if __name__ == "__main__": diff --git a/bin/do_epic/backend/test_jira.py b/bin/do_epic/backend/test_jira.py index 0337d938..38e3d86e 100644 --- a/bin/do_epic/backend/test_jira.py +++ b/bin/do_epic/backend/test_jira.py @@ -91,12 +91,12 @@ class FakeJira: return {"id": "1", "key": key} def ranked(self, body: object) -> object: - """Moves the one issue named just before or just after another, and answers no body, as Jira does for a rank it made.""" + """Moves the issue the body names to just before the other issue it names, and answers no body, as Jira does for a rank it made.""" assert isinstance(body, dict) - [key], other = body["issues"], body.get("rankBeforeIssue") or body["rankAfterIssue"] + [key], before = body["issues"], body["rankBeforeIssue"] moved = next(issue for issue in self.issues if issue["key"] == key) self.issues.remove(moved) - self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == other) + ("rankAfterIssue" in body), moved) + self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == before), moved) return None def change(self, key: str, **fields: object) -> None: diff --git a/bin/do_epic/ranking.py b/bin/do_epic/ranking.py index 488d9d54..b0b62418 100644 --- a/bin/do_epic/ranking.py +++ b/bin/do_epic/ranking.py @@ -60,35 +60,54 @@ def ranked(items: list[EpicItem], formula: str, epic_goals: str, repos: dict[str return blockers_first(scored) -def reranked(store: EpicStore, order: list[str]) -> None | Failure: - """Ranks the epic's child issues named in order, each one the loop filed, so the tracker's backlog lists them in order. Each other child issue, such as one a person filed, keeps its slot; the slots of the named issues take them in order's order. A sub-task holds no slot and follows its parent. +@dataclasses.dataclass(frozen=True) +class Rank: + """One rank to ask of a tracker: the issue named key just before the issue named before.""" + key: str + before: str - The walk goes from the backlog's end: an issue not just before the one that follows it in the target ranks just before that one, so only the loop's issues move. The target's last issue, where it isn't already last, ranks just after the issue that is. A rank the tracker refuses stops the walk, which fails naming it, since a wrongly ranked team backlog takes hours to restore; the ranks made before it stay.""" + +def reranked(store: EpicStore, order: list[str]) -> None | Failure: + """Re-ranks the tracker's backlog so that the child issues whose keys order lists come in that sequence. Each key must name a child issue the loop filed, and only once; otherwise the call fails before it ranks any issue. The listed issues change positions only with each other: every other child issue, such as one a person filed, stays at its position in the backlog. A sub-task has no position of its own and follows its parent. + + The first rank the tracker refuses ends the re-rank with a Failure that names it, since a wrongly ranked team backlog takes hours to restore; the ranks made before it stay.""" read = store.read() if isinstance(read, Failure): return read children = [issue for issue in read if issue.parent == store.epic_key] - if stray := next((key for key in order if key not in {issue.key for issue in children if issue.by_loop}), None): + ours = {issue.key for issue in children if issue.by_loop} + if stray := next((key for key in order if key not in ours), None): return Failure(f"{stray} is not one of the child issues of the epic {store.epic_key} that the loop filed, so the backlog was not re-ranked") if twice := next((key for key in order if order.count(key) > 1), None): return Failure(f"the order names {twice} twice, so the backlog was not re-ranked") - now = [issue.key for issue in children] - slots = iter(order) - target = [next(slots) if key in order else key for key in now] - for place in reversed(range(len(target))): - key = target[place] - at = now.index(key) - # The slices are empty past the end, so the last issue already in place is skipped too. - if key not in order or now[at + 1:at + 2] == target[place + 1:place + 2]: - continue - other, after = (now[-1], True) if place == len(target) - 1 else (target[place + 1], False) - if refused := store.rank(key, other, after): - return Failure(f"cannot rank {key} just {'after' if after else 'before'} {other}: {refused.reason}; the re-rank stopped there, so rank the loop's issues in {store.epic_key}'s backlog by hand as {', '.join(order)}") - now.remove(key) - now.insert(now.index(other) + after, key) + for rank in rank_moves([issue.key for issue in children], order): + if refused := store.rank(rank.key, rank.before): + return Failure(f"cannot rank {rank.key} just before {rank.before}: {refused.reason}; the re-rank stopped there, so rank the loop's issues in {store.epic_key}'s backlog by hand to come in this sequence: {', '.join(order)}") return None +def rank_moves(backlog: list[str], order: list[str]) -> list[Rank]: + """The ranks, in the sequence to make them, that turn backlog, a list of keys, into one where the keys order lists come in that sequence, each at a position one of them held, while every other key keeps its position. order names each key once, and each is in backlog. + + Working from the backlog's end, a listed key that isn't already just before the key due after it ranks just before that key. The key due last, where it isn't already last, ranks just before the key that is, which moves away in its own turn, since it is due earlier.""" + listed = set(order) + sequence = iter(order) + target = [next(sequence) if key in listed else key for key in backlog] + now = list(backlog) + ranks = [] + for position in reversed(range(len(target))): + key = target[position] + due_after = target[position + 1] if position + 1 < len(target) else None + at = now.index(key) + if key not in listed or (now[at + 1] if at + 1 < len(now) else None) == due_after: + continue + rank = Rank(key, now[-1] if due_after is None else due_after) + ranks.append(rank) + now.remove(key) + now.insert(now.index(rank.before), key) + return ranks + + def chain_scoring(formula: ast.Expression, epic_goals: str, repo: str | None, own: RepoRanking | None) -> ranking.Scoring | Failure: """How an item in repo scores: the chain's goals, and what each achieve goal weighs. The bar is 0, since a bar decides what is filed, and the order holds every item that was. diff --git a/bin/do_epic/test_ranking.py b/bin/do_epic/test_ranking.py index 9e19dce5..ec1b33ee 100644 --- a/bin/do_epic/test_ranking.py +++ b/bin/do_epic/test_ranking.py @@ -1,12 +1,13 @@ import dataclasses import decimal +import itertools import pathlib import sys import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from do_epic.ranking import chain, EpicItem, ranked, RepoRanking, reranked +from do_epic.ranking import chain, EpicItem, rank_moves, ranked, RepoRanking, reranked from failure import Failure from plan.todo_table import Item, parse_moves from do_epic.backend.fake import MemoryEpic @@ -157,23 +158,23 @@ class RankedTest(unittest.TestCase): class Recording(MemoryEpic): - """A MemoryEpic that keeps each rank asked of it, and refuses the one to rank the issue named in refused.""" + """A MemoryEpic that keeps each rank asked of it, and refuses every rank of the issue named in refused.""" refused: str | None = None - asked: list[tuple[str, str, bool]] + asked: list[tuple[str, str]] - def rank(self, key: str, other: str, after: bool = False) -> None | Failure: - self.asked.append((key, other, after)) - return Failure("Jira answered 403") if key == self.refused else super().rank(key, other, after) + def rank(self, key: str, before: str) -> None | Failure: + self.asked.append((key, before)) + return Failure("Jira answered 403") if key == self.refused else super().rank(key, before) def epic(*people: int, issues: int = 4) -> Recording: - """An epic of child issues ABC-100 onwards, the loop's apart from those whose places are in people.""" + """An epic whose child issues are ABC-100 onwards. The loop filed each of them, except those whose positions, counted from 0, are in people.""" store = Recording("ABC-12") store.asked = [] - for place in range(issues): - store.file("ABC-12", f"Item {place}.", "", ()) - if place in people: - store.change(f"ABC-{100 + place}", by_loop=False) + for position in range(issues): + store.file("ABC-12", f"Item {position}.", "", ()) + if position in people: + store.change(f"ABC-{100 + position}", by_loop=False) return store @@ -201,8 +202,8 @@ class RerankedTest(unittest.TestCase): def test_ranks_only_the_issues_out_of_place(self) -> None: store = epic(issues=5) - self.assertEqual(reranked(store, ["ABC-100", "ABC-101", "ABC-102", "ABC-104", "ABC-103"]), None) - self.assertEqual(store.asked, [("ABC-103", "ABC-104", True)]) + self.assertEqual(reranked(store, ["ABC-100", "ABC-102", "ABC-101", "ABC-103", "ABC-104"]), None) + self.assertEqual(store.asked, [("ABC-101", "ABC-103")]) def test_an_issue_the_order_doesnt_name_keeps_its_slot(self) -> None: store = epic() @@ -232,13 +233,13 @@ class RerankedTest(unittest.TestCase): def test_a_rank_the_tracker_refuses_stops_the_walk_and_names_the_order_to_finish_by_hand(self) -> None: store = epic() store.refused = "ABC-101" - self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100")) - self.assertEqual(store.asked, [("ABC-100", "ABC-103", True), ("ABC-101", "ABC-100", False)]) + self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand to come in this sequence: ABC-103, ABC-102, ABC-101, ABC-100")) + self.assertEqual(store.asked, [("ABC-100", "ABC-103"), ("ABC-101", "ABC-100")]) - def test_a_refused_rank_after_the_last_issue_names_it(self) -> None: + def test_a_refused_rank_of_the_issue_due_last_names_it(self) -> None: store = epic() store.refused = "ABC-100" - self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-100 just after ABC-103: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100")) + self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-100 just before ABC-103: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand to come in this sequence: ABC-103, ABC-102, ABC-101, ABC-100")) def test_a_read_that_fails_ranks_nothing(self) -> None: store = epic() @@ -247,5 +248,21 @@ class RerankedTest(unittest.TestCase): self.assertEqual(store.asked, []) +class RankMovesTest(unittest.TestCase): + def test_every_backlog_of_up_to_six_issues_reaches_its_target_moving_only_the_listed_keys(self) -> None: + for size in range(7): + backlog = [f"K-{n}" for n in range(size)] + for listed in itertools.chain.from_iterable(itertools.combinations(backlog, count) for count in range(size + 1)): + for order in itertools.permutations(listed): + sequence = iter(order) + target = [next(sequence) if key in listed else key for key in backlog] + now = list(backlog) + for rank in rank_moves(backlog, list(order)): + self.assertIn(rank.key, listed) + now.remove(rank.key) + now.insert(now.index(rank.before), rank.key) + self.assertEqual(now, target, (backlog, order)) + + if __name__ == "__main__": unittest.main() diff --git a/bin/plan_store/jira_epic.py b/bin/plan_store/jira_epic.py index 7663b99c..6f803c5f 100644 --- a/bin/plan_store/jira_epic.py +++ b/bin/plan_store/jira_epic.py @@ -156,7 +156,7 @@ class JiraPlan: notes.append(f"filed {key}, but cannot link it as blocked by {blocker}: {linked.reason}; link it in Jira") if isinstance(before, Failure): notes.append(f"filed {key}, but cannot rank it: {before.reason}; rank it in Jira") - elif before is not None and (refused := rank_refusal(self.epic.site, key, before, False, authorization, self.http)): + elif before is not None and (refused := rank_refusal(self.epic.site, key, before, authorization, self.http)): notes.append(f"filed {key}, but cannot rank it before {before}: {refused}; rank it in Jira") return tuple(notes) @@ -442,9 +442,9 @@ def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failu return searched(epic.site, f"{epic.key}'s children", f'parent = "{epic.key}" AND statusCategory != Done ORDER BY Rank ASC', {"fields": ["summary", "description", "fixVersions", "issuelinks"], "properties": [PROPERTY]}, authorization, http) -def rank_refusal(site: str, key: str, other: str, after: bool, authorization: str, http: Http) -> str | None: - """Ranks the issue named key just before the issue named other, or just after it where after is True; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors.""" - answer = http("PUT", f"{site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankAfterIssue" if after else "rankBeforeIssue": other}) +def rank_refusal(site: str, key: str, before: str, authorization: str, http: Http) -> str | None: + """Ranks the issue named key just before the issue named before; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors.""" + answer = http("PUT", f"{site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankBeforeIssue": before}) if isinstance(answer, Failure): return answer.reason entries = answer.get("entries") if isinstance(answer, dict) else None -- 2.52.0 From df5d5903fc4aaee0f4caeae6c56075b0aeeb7749 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 19:56:29 +0100 Subject: [PATCH 7/9] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20reword=20re?= =?UTF-8?q?ranked's,=20rank's=20and=20the=20test=20epic's=20docstrings,=20?= =?UTF-8?q?in=20the=20stability=20round's=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From cb52872452d3fd080191e683a8b2f066b4e76914 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 20:14:31 +0100 Subject: [PATCH 8/9] Name the comment call in the backend protocol's summary --- bin/do_epic/backend/protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/do_epic/backend/protocol.py b/bin/do_epic/backend/protocol.py index 3219820e..b48b314c 100644 --- a/bin/do_epic/backend/protocol.py +++ b/bin/do_epic/backend/protocol.py @@ -1,4 +1,4 @@ -"""What every backend of an epic's plan reads, files, labels and ranks: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes. +"""What every backend of an epic's plan reads, files, labels, comments on and ranks: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes. EpicStore is not plan_store's PlanStore. A PlanStore item names a release, but an epic item has none (`docs/decisions.md` → `do-epic: drives one Jira epic …`), and it may be a sub-task.""" import dataclasses -- 2.52.0 From 92f90bd2322af7a0f8b87ebfbe6195e28c2cdddf Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 20:15:49 +0100 Subject: [PATCH 9/9] Finish item 427 in the plan --- CHANGELOG.md | 1 + todo.md | 16 +--------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7228745..fef99718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- do-epic's epic backends rank a child issue just before another, in Jira and in memory, and do-epic can re-rank Jira's backlog to an epic's ranking: it moves only the issues the loop filed, so each issue a person filed keeps its place, and it stops at the first rank Jira refuses and names it. Nothing calls it yet. - Comprehension seats run as the `comprehension-seat` agent under `agents/`, which starts without `CLAUDE.md` and the skill and agent listings, and `larv-review prepare-scoring` no longer takes `--preloaded`; after updating, launch each seat with `subagent_type: comprehension-seat`. - do-epic splits an epic item that changes several repos into one Jira sub-task per repo, each labelled `repo:`, with a headless claude call predicting the repos from the code; the item is marked `split-by-repo` and counts as done once every sub-task is, and an issue a person filed gets a comment for the team in the epic's language. The epic backends gain `comment`, in the Jira backend and the in-memory one. - do-epic's epic backends read each issue's scores, its blockers and whether the loop filed it, in the Jira backend and the in-memory one; the Jira backend marks each issue it files as the loop's. Nothing calls it yet. diff --git a/todo.md b/todo.md index ed1cad9f..1e5d6c77 100644 --- a/todo.md +++ b/todo.md @@ -12,8 +12,7 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 427 | 0.12.0 | | | **Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed, so people's issues keep their rank.** | 3 | 2 | 3 | 6 | 3 | 1 by 5 | 1.9 | -| 410 | 0.12.0 | 427 | | **Run `do-epic `: one tmux session per epic, a window per chunk, up to the epic's cap of running chunks and each repo's `parallel-chunks`, and never in a repo a loop-claude is running chunks in.** | 3 | 2 | 3 | 6 | 6 | 1 by 5 | 0.8 | +| 410 | 0.12.0 | | | **Run `do-epic `: one tmux session per epic, a window per chunk, up to the epic's cap of running chunks and each repo's `parallel-chunks`, and never in a repo a loop-claude is running chunks in.** | 3 | 2 | 3 | 6 | 6 | 1 by 5 | 0.8 | | 416 | 0.12.0 | 410 | | **Finish an epic's repo item with a bullet under its repo's `CHANGELOG.md` → `## Unreleased`, or with none where the repo's plan is in Jira.** | 1 | 1 | 1 | 1 | 2 | 1 by 5 | 2.1 | | 413 | 0.12.0 | 410 | | **File a finding about an epic goal in the epic and one about a repo goal by that repo's rules, ask the human where unsure which, and give the judge the epic's records beside the repo's.** | 3 | 2 | 3 | 6 | 4 | 1 by 5 | 1.6 | | 415 | 0.12.0 | 410, 413 | | **Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 | @@ -79,19 +78,6 @@ ## Details -### 427. Re-rank Jira's backlog to match an epic's ranking, moving only the issues the loop filed, so people's issues keep their rank. - -Split from item 408 (`docs/decisions.md` → `do-epic: drives one Jira epic …`). `EpicStore` gains a rank call, in both backends and the contract tests. Lift `JiraPlan.rank_refusal` to a module function both stores call. Walk the target order: where the issue at a position isn't the target's, rank the target's just before it; the slots people's issues hold stay theirs. A rank Jira refuses stops the walk and is reported, since a wrongly ranked team backlog takes hours to restore. - -Touches: - -- `bin/plan_store/jira_epic.py`: `JiraPlan.rank_refusal` (small) -- `bin/do_epic/backend/protocol.py`: `EpicStore` (small) -- `bin/do_epic/backend/fake.py` -- `bin/do_epic/backend/jira.py` -- `bin/do_epic/backend/contract.py` -- `bin/do_epic/ranking.py` - ### 410. Run `do-epic `: one tmux session per epic, a window per chunk, up to the epic's cap of running chunks and each repo's `parallel-chunks`, and never in a repo a loop-claude is running chunks in. The lock that keeps do-epic and loop-claude apart is the per-project `starting` flock, shared by both (`docs/decisions.md` → `do-epic: drives one Jira epic …`). Each chunk routes on its repo's model and ladder, a no-repo chunk on the machine setting's model. `loop/chunk_windows.py` `start_chunks` is a place the seats found hard: make it easier to read where it changes. Where a do-epic cycle's worker, judge or human reads the driver's name, they read do-epic, never loop-claude: item 401 left `agent_cycle`'s own text naming loop-claude, since whether the markers that code matches (`TYPED_HERE`, `TRANSCRIPT_HEADING`) vary by driver depends on what do-epic calls itself and where it archives its cycles. The worker's prompt and the judge's rules share the phrase a worker asks for a higher rung with, so both take it from one place. -- 2.52.0