Apply lilleman's answers: maintain-restoring items are defects ranked after security, the most specific goal only, the reshape as the only work, bar 0.1

This commit is contained in:
2026-10-16 03:26:37 +02:00
parent a9a19fdbae
commit c2697c6281
8 changed files with 56 additions and 38 deletions
+9 -5
View File
@@ -5,7 +5,7 @@ usage: rank_todo.py [--check] [todo.md]
Reads todo.md (default: ./todo.md), the README.md beside it, and docs/decisions.md when there is
one. Rewrites each item's Score from the formula and sorts the items by release; within a release,
security rows come first, then the rest by score from highest, then by ID. Then it moves each blocker,
security rows come first, then defect rows, then the rest, each group by score from highest, then by ID. Then it moves each blocker,
an item another's Blocked by cell names, that ranks below an item it blocks to just above the first
such item. Orders the details to match. Adds the Blocked by column to a table
without it. --check writes nothing and fails when the file is not ranked as it would be.
@@ -44,7 +44,9 @@ A valid todo.md; ## Details and each item's detail are optional:
- An item's R, S and C are whole numbers from 1 to 10. C, how hard the change is to get right, stays
out of the formula.
- An item's Moves cell is empty, or names each achieve goal it moves and how far, a whole number
from 1 to 10, such as `1.1 by 8, 1.2 by 5`. An item that moves no achieve goal scores V 0.
from 1 to 10, such as `1.1 by 8, 1.2 by 5`: the most specific goal, and a parent only for a move
none of its sub-goals covers, so never a goal beside its own sub-goal. An item that moves no
achieve goal scores V 0.
- An item's Exempt cell is empty, or names why the bar does not apply: decision, defect, owner,
principle, question or security. An item docs/decisions.md cites as "`todo.md` item N" must be
exempt, and a row marked decision must be cited there.
@@ -81,9 +83,11 @@ LARGEST_FORMULA = 200
LONGEST_FORMULA = 4 * LARGEST_FORMULA
OPERATORS = (ast.Add, ast.BinOp, ast.Div, ast.Expression, ast.Load, ast.Mult, ast.Pow, ast.Sub, ast.UAdd, ast.UnaryOp, ast.USub)
WEIGHTS_HEADER = "| Goal | W |"
# The Exempt reasons that rank an item ahead of the rest of its release, in order: a security finding, then a defect, which a 🔴 or a broken maintain goal is.
FIRST = {"security": 0, "defect": 1}
# How README.md marks a goal; None where it marks it neither way.
Mark = typing.Literal["Maintain", "Achieve"] | None
RESHAPE = f"the items table scores A and G against goal weights todo.md states, the shape before {MOVES}; reshaping it to the shape rank_todo.py --help shows, after marking README.md's goals **Maintain:** or **Achieve:** and setting the bar on the new scale under every item to keep, is a chunk of its own"
RESHAPE = f"the items table scores A and G against goal weights todo.md states, the shape before {MOVES}. Until it has the shape rank_todo.py --help shows, reshaping it is the project's only work, as ~/.claude/CLAUDE.md → 'Working loop' says: mark README.md's goals **Maintain:** or **Achieve:**, name each item's {MOVES}, and set the bar on the new scale under every item to keep"
@dataclasses.dataclass(frozen=True)
@@ -233,14 +237,14 @@ def blocked_through(id_: int, items: list[Item]) -> set[int]:
def ordered(items: list[Item], scoring: Scoring) -> list[tuple[Item, float]] | Failure:
"""Each item with its score, by release, then security first, then by score from highest, then by ID; then each blocker above every item it blocks."""
"""Each item with its score, by release, then security first and defect next, then by score from highest, then by ID; then each blocker above every item it blocks."""
by_score = []
for item in items:
value = score(scoring.formula, item, scoring)
if isinstance(value, Failure):
return value
by_score.append((item, value))
by_score.sort(key=lambda pair: (pair[0].release, pair[0].exempt != "security", -pair[1], pair[0].id))
by_score.sort(key=lambda pair: (pair[0].release, FIRST.get(pair[0].exempt, len(FIRST)), -pair[1], pair[0].id))
return blockers_first(by_score)
+11 -1
View File
@@ -146,7 +146,7 @@ class Rank(unittest.TestCase):
def test_refuses_a_goal_it_cannot_weigh(self):
cases = {
(TODO.replace("2.1 by 8, 1 by 6", "2.1 by 8, 2 by 6"), README): "item 3 cites goal 2, a maintain goal, which vetoes and never scores; name only the achieve goals it moves",
(TODO.replace("2.1 by 8, 1 by 6", "1 by 8, 2 by 6"), README): "item 3 cites goal 2, a maintain goal, which vetoes and never scores; name only the achieve goals it moves",
(TODO.replace("2.1 by 8, 1 by 6", "2.1 by 8, 3 by 6"), README): "item 3 cites goal 3, which README.md's ## Goals does not number",
(TODO.replace("2.1 by 8, 1 by 6", "2.1 by 8, 2.1 by 6"), README): "item 3 cites goal 2.1 twice; name each goal once",
(TODO, README.replace("**Maintain:** Correct", "Correct")): "README.md's goal 2 is marked neither **Maintain:** nor **Achieve:**; mark it, as ~/.claude/rules/goals-and-audience.md says, so rank_todo.py knows which goals score",
@@ -155,6 +155,16 @@ class Rank(unittest.TestCase):
with self.subTest(reason=reason):
self.assertEqual(self.ranked(todo, readme), Failure(reason))
def test_ranks_defects_after_security_and_before_the_rest(self):
rows = [line.split(" | ")[0] for line in self.ranked(TODO.replace("| 2 | 0.1.0 | | |", "| 2 | 0.1.0 | | defect |")).text.splitlines() if line.startswith("| ") and " | 0." in line]
self.assertEqual(rows, ["| 4", "| 2", "| 3", "| 5", "| 1"])
def test_refuses_a_goal_named_beside_its_own_sub_goal(self):
readme = "## Goals\n\n1. **Achieve:** A.\n 1. **Maintain:** B.\n 2. **Achieve:** C.\n2. **Achieve:** D.\n"
todo = TODO.replace("2.1 by 8, 1 by 6", "1.2 by 2, 1 by 3").replace("| 2.1 by 1 |", "| 2 by 1 |")
self.assertEqual(self.ranked(todo, readme), Failure("item 3 names goal 1 beside its sub-goal 1.2; name only the most specific goal an item moves, and a parent only for a move none of its sub-goals covers"))
self.assertIsInstance(self.ranked(todo.replace("1.2 by 2, 1 by 3", "1.2 by 2, 2 by 3"), readme), rank_todo.Ranked)
def test_scores_every_item_zero_where_readme_marks_no_goal_achieve(self):
ranked = self.ranked(TODO.replace("2.1 by 8, 1 by 6", "").replace("| 2.1 by 1 |", "| |").replace("| 1 by 9 |", "| |"), README.replace("**Achieve:**", "**Maintain:**"))
self.assertEqual([line.split(" scores ")[0] for line in ranked.under_bar], ["item 2", "item 3", "item 1"])
+2
View File
@@ -47,6 +47,8 @@ def parse_moves(id_: str, cell: str) -> Moves | Failure:
goals = [goal for goal, _ in moves]
if repeated := [goal for goal in goals if goals.count(goal) > 1]:
return Failure(f"item {id_} cites goal {repeated[0]} twice; name each goal once")
if nested := [(parent, goal) for parent in goals for goal in goals if goal.startswith(parent + ".")]:
return Failure(f"item {id_} names goal {nested[0][0]} beside its sub-goal {nested[0][1]}; name only the most specific goal an item moves, and a parent only for a move none of its sub-goals covers")
return moves