Compute the next release, and whether work has landed towards it, in one function that chunk_pick and larv-review's scoring trigger share
This commit is contained in:
+42
-19
@@ -4,7 +4,7 @@ import re
|
||||
|
||||
from git_repo import commits_since, file_at, git, newest_release_tag
|
||||
from failure import Failure
|
||||
from todo_table import Item, items, next_item, renames
|
||||
from todo_table import Item, items, next_item, release_of, renames
|
||||
from markdown_text import sections
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -20,9 +20,20 @@ class LastCut:
|
||||
todos_since: list[str] | Failure
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Upcoming:
|
||||
"""The next release, and whether work has landed towards it, as `~/.claude/CLAUDE.md` → "Working loop" uses both."""
|
||||
# The earliest release after the last cut that todo.md has named since that cut or the plan holds; without a cut, the plan's earliest. None where there is none.
|
||||
release: tuple[int, int, int] | None
|
||||
# Whether work has landed towards it: one or more changes are unreleased, as unreleased_changes counts them.
|
||||
landed: bool | Failure
|
||||
# The last cut's version x.y.z, None where the newest v* tag names none.
|
||||
cut: tuple[int, int, int] | None
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Next:
|
||||
"""The plan's earliest release is the next release: the earliest after the last cut that todo.md has named since that cut. Without a cut, the plan's earliest release is the next."""
|
||||
"""The plan's earliest release is the next release."""
|
||||
# None where the plan holds no item.
|
||||
release: tuple[int, int, int] | None
|
||||
# The item the next chunk takes first, next_item's pick; None where every item waits or the plan holds none.
|
||||
@@ -36,15 +47,15 @@ class Cut:
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Finished:
|
||||
"""The next release holds no item, and changes are unreleased."""
|
||||
class ReadyToCut:
|
||||
"""The next release holds no item, and work has landed towards it."""
|
||||
# The next release, None where todo.md has named none since the cut.
|
||||
release: tuple[int, int, int] | None
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Unplanned:
|
||||
"""The next release holds no item, and no change is unreleased."""
|
||||
"""The next release holds no item, and no work has landed towards it."""
|
||||
# The next release, None where todo.md has named none since the cut.
|
||||
release: tuple[int, int, int] | None
|
||||
|
||||
@@ -54,8 +65,8 @@ class Unknown:
|
||||
"""todo.md's texts since the cut, or the changes since it, cannot be read."""
|
||||
|
||||
|
||||
# How the plan stands to the last cut, the version x.y.z the newest v* tag names, with the item the next chunk takes first where there is one.
|
||||
Pick = Next | Cut | Finished | Unplanned | Unknown
|
||||
# How the plan stands to the last cut, with the item the next chunk takes first where there is one.
|
||||
Pick = Next | Cut | ReadyToCut | Unplanned | Unknown
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -91,29 +102,41 @@ def todos_since(tag: str | None | Failure, ref: str, cwd: str) -> list[str] | Fa
|
||||
|
||||
def chunk_item(found: list[Item], cut: LastCut) -> Pick:
|
||||
"""The pick from todo.md's items, weighed against the last cut. Routing and chunk-preflight both pick with it, so they name one item."""
|
||||
return standing(cut.tag, unreleased_changes(cut), min((item.release for item in found), default=None), next_item(found), named_releases(cut.todos_since))
|
||||
earliest = min((item.release for item in found), default=None)
|
||||
upcoming = next_release(cut, earliest)
|
||||
return standing(upcoming, earliest, next_item(found)) if isinstance(upcoming, Upcoming) else upcoming
|
||||
|
||||
|
||||
def standing(tag: str | None | Failure, changes: int | Failure, earliest: tuple[int, int, int] | None, first: Item | None, named: set[tuple[int, int, int]] | Failure) -> Pick:
|
||||
"""How the plan stands to tag, the newest v* tag.
|
||||
def next_release(cut: LastCut, earliest: tuple[int, int, int] | None) -> Upcoming | Cut | Unknown:
|
||||
"""The next release after cut, and whether work has landed towards it. earliest is the plan's earliest release, None where the plan holds no item.
|
||||
|
||||
earliest is the plan's earliest release, None where the plan holds no item, and first is next_item's pick. changes counts the unreleased changes. named holds each release todo.md named since the tag.
|
||||
Cut where the plan files items under the last cut's version or earlier, and Unknown where todo.md's texts since the cut cannot be read.
|
||||
"""
|
||||
tagged = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", tag) if isinstance(tag, str) else None
|
||||
tagged = re.fullmatch(r"v([0-9]+\.[0-9]+\.[0-9]+)", cut.tag) if isinstance(cut.tag, str) else None
|
||||
changes = unreleased_changes(cut)
|
||||
landed = changes if isinstance(changes, Failure) else changes > 0
|
||||
if tagged is None:
|
||||
return Next(earliest, first)
|
||||
cut_version = tuple(int(part) for part in tagged.groups())
|
||||
return Upcoming(earliest, landed, None)
|
||||
cut_version = release_of(tagged[1])
|
||||
if earliest is not None and earliest <= cut_version:
|
||||
return Cut(earliest)
|
||||
named = named_releases(cut.todos_since)
|
||||
if isinstance(named, Failure):
|
||||
return Unknown()
|
||||
first_named = min((release for release in named if release > cut_version), default=None)
|
||||
if earliest is not None and (first_named is None or earliest <= first_named):
|
||||
after = {release for release in named if release > cut_version} | ({earliest} if earliest is not None else set())
|
||||
return Upcoming(min(after, default=None), landed, cut_version)
|
||||
|
||||
|
||||
def standing(upcoming: Upcoming, earliest: tuple[int, int, int] | None, first: Item | None) -> Next | ReadyToCut | Unplanned | Unknown:
|
||||
"""How the plan stands to the next release, upcoming. earliest is the plan's earliest release, None where the plan holds no item, and first is next_item's pick.
|
||||
|
||||
Without a cut, or where the plan's earliest release is the next, the next chunk takes first. Else the next release holds no item, and is ready to cut once work has landed towards it, or else to plan.
|
||||
"""
|
||||
if upcoming.cut is None or (earliest is not None and earliest == upcoming.release):
|
||||
return Next(earliest, first)
|
||||
# The plan's earliest release is past the next release, or the plan holds none: the next release holds no item.
|
||||
if isinstance(changes, Failure):
|
||||
if isinstance(upcoming.landed, Failure):
|
||||
return Unknown()
|
||||
return Finished(first_named) if changes else Unplanned(first_named)
|
||||
return ReadyToCut(upcoming.release) if upcoming.landed else Unplanned(upcoming.release)
|
||||
|
||||
|
||||
def unreleased_changes(cut: LastCut) -> int | Failure:
|
||||
|
||||
Reference in New Issue
Block a user