Answer stability round 2: 0 🔴, 2 🟡; take the next release as the earliest todo.md has named since the last cut, so an emptied patch or a major jump stops the loop too, count work landed by the Unreleased entries before commits, read the default branch once, and test the emptied release and the stalled origin through real git

This commit is contained in:
2026-10-17 02:34:15 +02:00
parent 4cf3c2bd8c
commit 5ba8920dbf
13 changed files with 224 additions and 142 deletions
+44 -13
View File
@@ -3,7 +3,7 @@ import re
import typing
from failure import Failure
from markdown_text import FENCE
from markdown_text import FENCE, sections
# Each score a Shape names, and each goal's move, runs from 1 to TOP_SCORE, but for the levels L, E and I, which run from 1 to their LEVELS: ~/.claude/rules/todo-items.md defines each level.
TOP_SCORE = 10
@@ -17,8 +17,8 @@ BLOCKED_BY = "Blocked by"
MOVES = "Moves"
# How the items table's header opens, which tells it from any other table in todo.md.
HEADER_START = "| ID | Release |"
# How the plan's earliest release stands to the version x.y.z the newest tag names. "next": it is x.y.z+1, x.y+1.0 or x+1.0.0, or no tag names a version. "cut": it is x.y.z or earlier.
# Else the release after the tag holds no item: "finished" where commits followed the tag, "unplanned" where none did, and "unknown" where they cannot be counted.
# How the plan's earliest release stands to the version x.y.z the newest tag names, the last cut. "next": it is the earliest release after x.y.z that todo.md has named since the cut, or no tag names a version. "cut": it is x.y.z or earlier.
# Else the next release, the earliest named since the cut, holds no item: "finished" where work landed since the cut, "unplanned" where none did, and "unknown" where that cannot be read.
Standing = typing.Literal["next", "cut", "finished", "unplanned", "unknown"]
# todo.md's ## Details section, its body the first group.
DETAILS = re.compile(r"^## Details\n(.*?)(?=^## |\Z)", re.M | re.S)
@@ -176,24 +176,55 @@ def next_item(found: list[Item]) -> Item | None:
return next((item for item in found if item.release == release and item.id not in waits), None)
def standing(tag: str | None | Failure, commits: int | Failure, earliest: tuple[int, int, int] | None) -> Standing:
"""How the plan's earliest release, None where the plan holds no item, stands to the newest v* tag, as Standing says; commits counts those after the tag."""
@dataclasses.dataclass(frozen=True)
class LastCut:
"""What the default branch holds about its last release, which chunk_item weighs the plan against."""
# The newest v* tag, None where the branch has none.
tag: str | None | Failure
# CHANGELOG.md's text, empty where the branch holds none.
changelog: str | Failure
# How many commits follow the tag, or make up the branch where it has none.
commits: int | Failure
# todo.md's text at the tag and at each later commit that changed it; empty without a tag.
todos_since: list[str] | Failure
def unreleased_entries(changelog: str) -> int | None:
"""How many top-level `- ` entries CHANGELOG.md holds under ## Unreleased; None without that section."""
found = sections(changelog).get("Unreleased")
return None if found is None else sum(line.startswith("- ") for line in found[0].splitlines())
def landed(cut: LastCut) -> int | Failure:
"""How much work has landed since the last cut: the entries under ## Unreleased, or the commits since the tag where CHANGELOG.md has no such section, as `~/.claude/CLAUDE.md` → "Working loop" counts unreleased changes."""
entries = unreleased_entries(cut.changelog) if isinstance(cut.changelog, str) else None
return cut.commits if entries is None else entries
def named_releases(todos: list[str] | Failure) -> set[tuple[int, int, int]]:
"""Each release the todo.md texts file items under. A text that does not parse names none, and so does a history that cannot be read, which leaves the plan's earliest release as the next."""
found = [items(todo) for todo in todos] if isinstance(todos, list) else []
return {item.release for parsed in found if isinstance(parsed, list) for item in parsed}
def standing(tag: str | None | Failure, landed: int | Failure, earliest: tuple[int, int, int] | None, named: set[tuple[int, int, int]]) -> Standing:
"""How the plan's earliest release, None where the plan holds no item, stands to the newest v* tag, as Standing says. named holds each release todo.md named since that tag, and landed the work landed since it."""
cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", tag) if isinstance(tag, str) else None
if cut is None:
return "next"
major, minor, patch = (int(part) for part in cut.groups())
if earliest in ((major, minor, patch + 1), (major, minor + 1, 0), (major + 1, 0, 0)):
return "next"
if earliest is not None and earliest <= (major, minor, patch):
version = tuple(int(part) for part in cut.groups())
if earliest is not None and earliest <= version:
return "cut"
if isinstance(commits, Failure):
if earliest is not None and earliest == min(release for release in named | {earliest} if release > version):
return "next"
if isinstance(landed, Failure):
return "unknown"
return "finished" if commits else "unplanned"
return "finished" if landed else "unplanned"
def chunk_item(found: list[Item], tag: str | None | Failure, commits: int | Failure) -> tuple[Standing, Item | None]:
def chunk_item(found: list[Item], cut: LastCut) -> tuple[Standing, Item | None]:
"""The item the next chunk takes first, next_item's pick, where standing finds the plan's earliest release the next; else None. Routing and chunk-preflight both pick with it, so they name one item; standing comes with it, so a caller can say why there is none."""
stands = standing(tag, commits, min((item.release for item in found), default=None))
stands = standing(cut.tag, landed(cut), min((item.release for item in found), default=None), named_releases(cut.todos_since))
return stands, next_item(found) if stands == "next" else None