Rank each todo.md blocker just above the first item it blocks, allow no other order in todo.md, and route loop-claude on the first item that waits on nothing

This commit is contained in:
2026-10-15 22:54:47 +02:00
parent 545f3c3478
commit 5b7da27a5a
12 changed files with 269 additions and 151 deletions
+16 -6
View File
@@ -6,10 +6,15 @@ from failure import Failure
# Each of R, S, C, A and G runs from 1 to TOP_SCORE.
TOP_SCORE = 10
EXEMPTIONS = ("", "decision", "defect", "owner", "principle", "question", "security")
COLUMNS = ("ID", "Release", "Exempt", "Item", "R", "S", "C", "A", "G", "Goals", "Score")
# The column naming the items that block an item: each must be done before the item starts.
BLOCKED_BY = "Blocked by"
COLUMNS = ("ID", "Release", BLOCKED_BY, "Exempt", "Item", "R", "S", "C", "A", "G", "Goals", "Score")
ITEMS_HEADER = "| " + " | ".join(COLUMNS) + " |"
# Tables in git history from before C joined lack it; items() still parses them, though rank_todo refuses one in a checkout.
WITHOUT_C = "| " + " | ".join(column for column in COLUMNS if column != "C") + " |"
# A table from before BLOCKED_BY joined lacks it; items() parses it as blocked by nothing, and rank_todo adds the column.
WITHOUT_BLOCKERS = "| " + " | ".join(column for column in COLUMNS if column != BLOCKED_BY) + " |"
# Tables in git history from before C joined lack it too; items() still parses them, though rank_todo refuses one in a checkout.
WITHOUT_C = "| " + " | ".join(column for column in COLUMNS if column not in (BLOCKED_BY, "C")) + " |"
HEADERS = (ITEMS_HEADER, WITHOUT_BLOCKERS, WITHOUT_C)
@dataclasses.dataclass(frozen=True)
@@ -20,6 +25,8 @@ class Item:
tagline: str
scores: dict[str, int]
goals: tuple[str, ...]
# The IDs of the items that block it.
blocked_by: tuple[int, ...] = ()
@property
def risk_and_complexity(self) -> int:
@@ -35,9 +42,9 @@ class Table:
def items(todo: str) -> list[Item] | None | Failure:
"""Each row of a todo.md's items table, with C or without it; None where todo.md holds no items table."""
"""Each row of a todo.md's items table, with or without BLOCKED_BY and C; None where todo.md holds no items table."""
lines = todo.splitlines()
headers = [header for header in (ITEMS_HEADER, WITHOUT_C) if header in lines]
headers = [header for header in HEADERS if header in lines]
if not headers:
return None
table = table_rows(lines, headers[0])
@@ -92,6 +99,9 @@ def parse_row(row: str, header: str = ITEMS_HEADER) -> Item | Failure:
if not re.fullmatch(r"[0-9]+", named[name]) or not 1 <= int(named[name]) <= TOP_SCORE:
return Failure(f"item {id_}'s {name} {named[name]!r} is not a whole number from 1 to {TOP_SCORE}")
scores[name] = int(named[name])
blockers = named.get(BLOCKED_BY, "")
if not re.fullmatch(r"([0-9]+(, [0-9]+)*)?", blockers):
return Failure(f"item {id_}'s {BLOCKED_BY} {blockers!r} is not empty or IDs separated by \", \"")
cited = tuple(goal.strip() for goal in named["Goals"].split(","))
major, minor, patch = (int(part) for part in release.split("."))
return Item(int(id_), (major, minor, patch), exempt, tagline, scores, cited)
return Item(int(id_), (major, minor, patch), exempt, tagline, scores, cited, tuple(int(blocker) for blocker in blockers.split(", ") if blocker))