Answer architecture round 1: 1 🔴, 10 🟡; move FLOOR into comprehension_history, renumber the counter-signal item 198, void code health on a comprehension-check opt-out, add code health to every goal check, fail record-scoring on a failed re-rank, reuse overall_cells, and ease Scoring, parse_item and parse_moves

This commit is contained in:
2026-10-18 20:04:36 +02:00
parent 9e6715e0bf
commit 8e0060be08
18 changed files with 115 additions and 77 deletions
+48 -36
View File
@@ -44,7 +44,8 @@ A valid todo.md; ## Details and each item's detail are optional:
With 15 they weigh 0.082 and 0.053. Code health then weighs 4 times that while the overall of
docs/comprehension-history.md's newest scoring run is under 7.0, or there is none. A line
`**Void:** code health, since <reason>.` in README.md's ## Goals drops code health, and an item
may not name it. Only an item marked defect may name a maintain goal, the one it restores, which
may not name it. A project whose docs/decisions.md has a `## review opt-out:` title naming the
comprehension check must void it. Only an item marked defect may name a maintain goal, the one it restores, which
weighs as the heaviest achieve goal.
- The bar is judged on the Score as shown, to one decimal.
- A new item takes Next ID, and Next ID then goes up by one; every ID stays below it.
@@ -89,8 +90,7 @@ import typing
from todo_table import BLOCKED_BY, cells, CODE_HEALTH, DETAILS, HEADER_START, Item, item_details, items_table, MOVES, OLD_SHAPE, parse_row, renames, risk, Shape, SHAPE, shape_of, Table, table_rows, version
from failure import Failure
from larv_review.scoring import FLOOR
from comprehension_history import latest_overall
from comprehension_history import FLOOR, latest_overall
from markdown_text import listed, sections
from file_writes import replace_file
@@ -98,8 +98,10 @@ from file_writes import replace_file
GOAL_STEP = 0.97
# How many times its weight code health weighs while the comprehension panel's overall is under FLOOR, or unmeasured; lilleman's choice, which docs/decisions.md records.
UNDER_FLOOR = 4
# The line of README.md's ## Goals that voids code health, as ~/.claude/rules/goals-and-audience.md spells it.
# The line of README.md's ## Goals that voids code health, as ~/.claude/CLAUDE.md → "Shared goal" spells it.
VOID = re.compile(r"^\*\*Void:\*\* (.*)$", re.M)
# A docs/decisions.md title opting the project out of the comprehension check, as larv-review's SKILL.md → "Opt-out" spells it.
OPTED_OUT = re.compile(r"^## review opt-out:.*\bcomprehension check\b", re.M)
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)
@@ -117,9 +119,9 @@ class Scoring:
formula: ast.Expression
bar: float
next_id: int
# The goals an item may name, in rank order, each with its mark: code health first, unless README.md voids it or the table is in OLD_SHAPE, then README.md's goals in reading order.
# The goals an item may name, in rank order, each with its mark: code health first, unless README.md voids it, then README.md's goals in reading order.
goals: dict[str, Mark]
# The weight of each goal an item may name: in OLD_SHAPE every goal, at the weight todo.md states; else each goal goal_weights weighs.
# The weight of each goal an item may name: in OLD_SHAPE each of README.md's goals, at the weight todo.md states; else each goal goal_weights weighs.
weights: dict[str, float]
@@ -211,7 +213,7 @@ def rank(text: str, readme: str, decisions: str, history: str) -> Ranked | Failu
if isinstance(table, Failure):
return table
shape = shape_of(table.columns)
scoring = read_scoring(text, lines, readme, history, shape)
scoring = read_scoring(text, lines, readme, decisions, history, shape)
if isinstance(scoring, Failure):
return scoring
items = read_items(table, scoring)
@@ -283,8 +285,8 @@ def under_the_bar(item: Item, value: float, bar: float, items: list[Item]) -> st
return f"item {item.id} scores {value:.1f}, under the bar {bar:g}; delete it{blocked}, or mark it with a reason the bar does not apply"
def read_scoring(text: str, lines: list[str], readme: str, history: str, shape: Shape) -> Scoring | Failure:
goals = readme_goals(readme)
def read_scoring(text: str, lines: list[str], readme: str, decisions: str, history: str, shape: Shape) -> Scoring | Failure:
goals = ranked_goals(readme, decisions)
if isinstance(goals, Failure):
return goals
formula = parse_formula(stated(text, "Score"), variables(shape))
@@ -296,28 +298,37 @@ def read_scoring(text: str, lines: list[str], readme: str, history: str, shape:
next_id = stated(text, "Next ID")
if isinstance(next_id, Failure) or not re.fullmatch(r"[0-9]+", next_id):
return next_id if isinstance(next_id, Failure) else Failure(f"Next ID {next_id!r} is not a whole number")
weighed = weigh(lines, readme, history, goals, shape)
if isinstance(weighed, Failure):
return weighed
return Scoring(shape, formula, bar, int(next_id), *weighed)
weights = weigh(lines, history, goals, shape)
if isinstance(weights, Failure):
return weights
return Scoring(shape, formula, bar, int(next_id), dict(goals), weights)
def weigh(lines: list[str], readme: str, history: str, goals: list[tuple[str, Mark]], shape: Shape) -> tuple[dict[str, Mark], dict[str, float]] | Failure:
"""The goals an item may name, in rank order, and each one's weight. In OLD_SHAPE they are README.md's goals at the weights todo.md states. Otherwise code health comes first, unless README.md voids it, then README.md's goals, at the weights goal_weights gives them."""
def ranked_goals(readme: str, decisions: str) -> list[tuple[str, Mark]] | Failure:
"""Every goal an item may name, in rank order, each with its mark: code health first, unless README.md voids it, then README.md's goals in reading order. A void of anything else fails, and so does a docs/decisions.md that opts out of the comprehension check where README.md keeps code health, since the goal then has no signal."""
goals = readme_goals(readme)
if isinstance(goals, Failure):
return goals
voids = VOID.findall("".join(sections(readme).get("Goals", [])))
if other := [void for void in voids if not void.startswith(f"{CODE_HEALTH}, since ")]:
return Failure(f"README.md's ## Goals voids `{other[0]}`; only code health may be voided, as `**Void:** {CODE_HEALTH}, since <reason>.`")
if voids:
return goals
if OPTED_OUT.search(decisions):
return Failure(f"docs/decisions.md opts out of the comprehension check, so code health has no signal; void it in README.md's ## Goals with `**Void:** {CODE_HEALTH}, since <reason>.`, as ~/.claude/CLAUDE.md → 'Shared goal' says")
return [(CODE_HEALTH, "Achieve"), *goals]
def weigh(lines: list[str], history: str, goals: list[tuple[str, Mark]], shape: Shape) -> dict[str, float] | Failure:
"""Each goal's weight. In OLD_SHAPE, README.md's goals weigh what todo.md states, and code health nothing. Otherwise goal_weights gives each its weight, at the overall of the history's newest scoring run where the goals hold code health."""
if shape is OLD_SHAPE:
stated_weights = parse_weights(lines, [number for number, _ in goals])
return stated_weights if isinstance(stated_weights, Failure) else (dict(goals), stated_weights)
return parse_weights(lines, [number for number, _ in goals if number != CODE_HEALTH])
if WEIGHTS_HEADER in lines:
return Failure(f"todo.md holds a goal weights table beside a {MOVES} column; drop the table, since rank_todo.py weighs each achieve goal by its position in README.md")
voided = voids_code_health(readme)
if isinstance(voided, Failure):
return voided
overall = latest_overall(history)
overall = latest_overall(history) if CODE_HEALTH in dict(goals) else None
if isinstance(overall, Failure):
return overall
ranked = goals if voided else [(CODE_HEALTH, "Achieve"), *goals]
weights = goal_weights(ranked, overall)
return weights if isinstance(weights, Failure) else (dict(ranked), weights)
return goal_weights(goals, overall)
def read_table(lines: list[str]) -> Table | Failure:
@@ -455,14 +466,6 @@ def readme_goals(readme: str) -> list[tuple[str, Mark]] | Failure:
return goals
def voids_code_health(readme: str) -> bool | Failure:
"""Whether README.md's ## Goals voids code health; a void of anything else fails."""
voids = VOID.findall("".join(sections(readme).get("Goals", [])))
if other := [void for void in voids if not void.startswith(f"{CODE_HEALTH}, since ")]:
return Failure(f"README.md's ## Goals voids `{other[0]}`; only code health may be voided, as `**Void:** {CODE_HEALTH}, since <reason>.`")
return bool(voids)
def goal_weights(goals: list[tuple[str, Mark]], overall: decimal.Decimal | None) -> dict[str, float] | Failure:
"""Each achieve goal's weight: the one ranked k of n weighs GOAL_STEP ** (k - 1) / (1 + GOAL_STEP + ... + GOAL_STEP ** (n - 1)), so the weights sum to 1. Code health, where goals holds it, then weighs UNDER_FLOOR times that while the overall is under FLOOR or None, and the other goals keep their weights. Each maintain goal weighs as the heaviest achieve goal, since a broken one outranks any achieve goal; only a defect that restores it may name it. Every weight is 0 where README.md marks no goal **Achieve:**, so every item scores V 0 and only an exempt one passes the bar."""
if unmarked := [number for number, mark in goals if mark is None]:
@@ -595,13 +598,23 @@ def parse_weights(lines: list[str], goals: list[str]) -> dict[str, float] | Fail
def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure:
"""The row as an item whose goals README.md's hold; in SHAPE, with the R its L, E and I give."""
item = parse_row(row, table)
if isinstance(item, Failure):
return item
if broken := cited_goals_failure(item, scoring):
return broken
if scoring.shape is OLD_SHAPE:
if unknown := [goal for goal, _ in item.moves if goal not in scoring.weights]:
return Failure(f"item {item.id} cites goal {', '.join(unknown)}, which the goal weights do not list")
return item
# R is written here, as the Score is, so --check finds a stale one, and a reader keeps the R the table stored.
return dataclasses.replace(item, scores=item.scores | {"R": risk(item.scores["L"], item.scores["E"], item.scores["I"])})
def cited_goals_failure(item: Item, scoring: Scoring) -> Failure | None:
"""Why the goals the item names break README.md's; None when they hold. todo_table's parse_moves holds the rules a Moves cell keeps on its own."""
if scoring.shape is OLD_SHAPE:
unknown = [goal for goal, _ in item.moves if goal not in scoring.weights]
return Failure(f"item {item.id} cites goal {', '.join(unknown)}, which the goal weights do not list") if unknown else None
for goal, _ in item.moves:
if goal == CODE_HEALTH and goal not in scoring.goals:
return Failure(f"item {item.id} names {CODE_HEALTH}, which README.md voids; drop it from the item's {MOVES}, or the void from README.md")
@@ -609,8 +622,7 @@ def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure:
return Failure(f"item {item.id} cites goal {goal}, which README.md's ## Goals does not number")
if scoring.goals[goal] == "Maintain" and item.exempt != "defect":
return Failure(f"item {item.id} cites goal {goal}, a maintain goal, which only a defect that restores it may name; name the achieve goals the item moves")
# R is written here, as the Score is, so --check finds a stale one, and a reader keeps the R the table stored.
return dataclasses.replace(item, scores=item.scores | {"R": risk(item.scores["L"], item.scores["E"], item.scores["I"])})
return None
def render_item(item: Item, value: float, shape: Shape, columns: tuple[str, ...]) -> str: