Anchor each level of L, E and I with shipped items, and have score-outcomes list them for a scorer to compare against
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ A valid todo.md; ## Details and each item's detail are optional:
|
||||
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.
|
||||
- An item's L, E and I are levels that ~/.claude/rules/todo-items.md anchors: L from 1 to 4, E from 1
|
||||
- An item's L, E and I are levels that ~/.claude/rules/todo-items.md defines: L from 1 to 4, E from 1
|
||||
to 3 and I from 1 to 5.
|
||||
rank_todo.py writes its R, L + E + I - 2, at least 7 when I is 5 and at least 5 when I is 4. Its S
|
||||
is a whole number from 1 to 10.
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import re
|
||||
|
||||
from failure import Failure
|
||||
from todo_table import LEVELS
|
||||
from score_outcomes.outcomes import Outcome, render
|
||||
|
||||
# Where a project names the shipped items that show each level of L, E and I.
|
||||
ANCHORS = "docs/score-anchors.md"
|
||||
# One row of its table: a level, such as `L 1`, and the IDs of the items that show it.
|
||||
ROW = re.compile(r"\|\s*([A-Z]) ([0-9]+)\s*\|\s*([0-9]+(?:\s*,\s*[0-9]+)*)\s*\|")
|
||||
# The table's header and separator rows.
|
||||
FRAME = re.compile(r"\|\s*Level\s*\|\s*Items\s*\||\|[-|\s]+\|")
|
||||
|
||||
|
||||
def anchors(text: str) -> list[tuple[str, tuple[int, ...]]] | Failure:
|
||||
"""Each level the anchors table names, such as `L 1`, with its items' IDs, in the file's order."""
|
||||
found: list[tuple[str, tuple[int, ...]]] = []
|
||||
for row in (line.strip() for line in text.splitlines() if line.strip().startswith("|")):
|
||||
if FRAME.fullmatch(row):
|
||||
continue
|
||||
matched = ROW.fullmatch(row)
|
||||
if not matched or not 1 <= int(matched[2]) <= LEVELS.get(matched[1], 0):
|
||||
scales = ", ".join(f"{name} 1 to {top}" for name, top in LEVELS.items())
|
||||
return Failure(f"{ANCHORS} cannot read the row {row}; each row names a level, {scales}, and the IDs of shipped items, such as | L 1 | 12, 14 |")
|
||||
level = f"{matched[1]} {matched[2]}"
|
||||
if level in dict(found):
|
||||
return Failure(f"{ANCHORS} names {level} twice")
|
||||
found.append((level, tuple(int(id_) for id_ in matched[3].split(","))))
|
||||
return found
|
||||
|
||||
|
||||
def anchor_lines(found: list[tuple[str, tuple[int, ...]]], outcomes: list[Outcome]) -> list[str]:
|
||||
"""Each level, then each of its anchors with what its chunk measured."""
|
||||
by_id = {outcome.item.id: outcome for outcome in outcomes}
|
||||
lines = []
|
||||
for level, ids in found:
|
||||
lines.append(f"{level}:")
|
||||
lines += [render(by_id[id_]) if id_ in by_id else f"- Item {id_}: no merge commit on the default branch shipped it." for id_ in ids]
|
||||
return lines
|
||||
@@ -23,12 +23,17 @@ its table also had A, G and Goals. The chunk measures:
|
||||
|
||||
A project that merges without merge commits, by fast-forward or squash, has no chunk to measure.
|
||||
|
||||
Given L, E and I, on the levels ~/.claude/rules/todo-items.md anchors, and S, it works out R from
|
||||
Given L, E and I, on the levels ~/.claude/rules/todo-items.md defines, and S, it works out R from
|
||||
L, E and I, as rank_todo.py does, and lists the 5 finished items whose guesses sit closest, closest
|
||||
first: the least mean squared difference over the scores both hold, so R and S alone for an item
|
||||
scored before L, E and I, the newest first among equals. Each line gives what the item's chunk
|
||||
measured, which items shipped with it, and its tagline.
|
||||
|
||||
Then the project's anchors, the shipped items its docs/score-anchors.md names for each level of L,
|
||||
E and I, read from the checkout's working tree, each line as above, or that no merge shipped it. Exit 1
|
||||
on a row that names no level on its scale, a level named twice, or an Items cell that is not a list
|
||||
of IDs.
|
||||
|
||||
Then the median of the outcome R and S each predict at each value they were guessed at: R against
|
||||
🔴 findings, S against lines changed. And how well L, E and I each order chunks by review rounds
|
||||
past each pass's first and by 🔴 findings: Spearman's rank correlation, from -1 to +1, where +1
|
||||
@@ -39,10 +44,12 @@ hold it and its outcomes.
|
||||
Exit 1, saying why, on bad arguments, when git cannot start, finds no checkout or reads a shallow
|
||||
clone, or the default branch cannot be read.
|
||||
"""
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
from git_repo import default_branch, file_at, full_history, git
|
||||
from score_outcomes.anchors import anchor_lines, ANCHORS, anchors
|
||||
from git_repo import default_branch, file_at, full_history, git, top
|
||||
from failure import Failure
|
||||
from todo_table import LEVELS, risk, TOP_SCORE
|
||||
from markdown_text import listed
|
||||
@@ -70,12 +77,18 @@ def main(argv: list[str]) -> int:
|
||||
outcomes = read_outcomes(default)
|
||||
if isinstance(outcomes, Failure):
|
||||
return failed(outcomes)
|
||||
anchored = read_anchors()
|
||||
if isinstance(anchored, Failure):
|
||||
return failed(anchored)
|
||||
if argv:
|
||||
given = dict(zip(GIVEN, map(int, argv)))
|
||||
given["R"] = risk(given["L"], given["E"], given["I"])
|
||||
print(f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {given['R']}, and S {given['S']}, closest first:\n")
|
||||
print("\n".join(render(outcome) for outcome in nearest(outcomes, given)) or "- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none.")
|
||||
print()
|
||||
print(f"Anchors in {ANCHORS}, each level's shipped items:\n")
|
||||
print("\n".join(anchor_lines(anchored, outcomes)) or f"- None: the project's {ANCHORS} names no level; ~/.claude/rules/todo-items.md says how to choose them.")
|
||||
print()
|
||||
print("Median outcome at each guessed score, among chunks that shipped one item:\n")
|
||||
print("\n".join(report(outcomes)))
|
||||
return 0
|
||||
@@ -86,6 +99,19 @@ def failed(failure: Failure) -> int:
|
||||
return 1
|
||||
|
||||
|
||||
def read_anchors() -> list[tuple[str, tuple[int, ...]]] | Failure:
|
||||
"""The checkout's anchors as its working tree holds them, so a branch that edits them shows its edit; none where it has no such file."""
|
||||
root = top()
|
||||
if isinstance(root, Failure):
|
||||
return root
|
||||
try:
|
||||
return anchors((pathlib.Path(root) / ANCHORS).read_text())
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"cannot read {ANCHORS}: {failure}")
|
||||
|
||||
|
||||
def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
if partial := full_history():
|
||||
return partial
|
||||
|
||||
@@ -7,6 +7,8 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from score_outcomes.anchors import anchor_lines, anchors
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item
|
||||
from score_outcomes.outcomes import nearest, Outcome, outcomes_of, rank_correlation, render, report, shipped
|
||||
@@ -119,6 +121,23 @@ class Render(unittest.TestCase):
|
||||
self.assertIn("1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa, with item 5. ", render(outcome(4, 2, 3, 4, rounds=1, shipped_with=(5,))))
|
||||
|
||||
|
||||
ANCHORS = "# Score anchors\n\nWhy these.\n\n| Level | Items |\n|---|---|\n| L 1 | 4, 9 |\n| I 3 | 5 |\n"
|
||||
|
||||
|
||||
class Anchors(unittest.TestCase):
|
||||
def test_reads_each_levels_items_in_the_files_order(self):
|
||||
self.assertEqual(anchors(ANCHORS), [("L 1", (4, 9)), ("I 3", (5,))])
|
||||
|
||||
def test_refuses_a_level_off_its_scale_a_score_without_levels_a_repeated_level_or_an_unreadable_row(self):
|
||||
for row in ("| L 5 | 4 |", "| E 0 | 4 |", "| S 3 | 4 |", "| L 1 | 7 |", "| L 2 | four |", "| L 2 | |"):
|
||||
with self.subTest(row):
|
||||
self.assertIsInstance(anchors(ANCHORS + row + "\n"), Failure)
|
||||
|
||||
def test_lists_each_anchor_with_what_its_chunk_measured_and_says_which_it_cannot_find(self):
|
||||
lines = anchor_lines([("L 1", (4, 9))], [outcome(4, 2, 3, None, findings=(1, 2))])
|
||||
self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no merge commit on the default branch shipped it."])
|
||||
|
||||
|
||||
class ScoreOutcomesTool(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
@@ -155,6 +174,30 @@ class ScoreOutcomesTool(unittest.TestCase):
|
||||
self.assertIn("- Item 4, R 2, S 3, C 10: 3 lines in 1 file, 0 rounds past each pass's first, 1 🔴, 2 🟡; merged ", ran.stdout)
|
||||
self.assertNotIn("Item 5", ran.stdout)
|
||||
|
||||
def test_lists_the_projects_anchors_with_what_their_chunks_measured(self):
|
||||
self.git("switch", "-q", "-c", "chunk")
|
||||
self.commit("Do it", {"a.py": "1\n", "todo.md": todo(SECOND)})
|
||||
self.git("switch", "-q", "main")
|
||||
self.git("merge", "-q", "--no-ff", "-m", "Merge chunk", "chunk")
|
||||
(self.checkout / "docs").mkdir()
|
||||
(self.checkout / "docs" / "score-anchors.md").write_text(ANCHORS)
|
||||
ran = self.run_tool("1", "2", "1", "3")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertIn("Anchors in docs/score-anchors.md, each level's shipped items:\n\nL 1:\n- Item 4, R 2, S 3, C 10: 1 line in 1 file", ran.stdout)
|
||||
self.assertIn("I 3:\n- Item 5: no merge commit on the default branch shipped it.", ran.stdout)
|
||||
|
||||
def test_says_where_anchors_go_when_the_project_has_none(self):
|
||||
ran = self.run_tool()
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertIn("- None: the project's docs/score-anchors.md names no level; ~/.claude/rules/todo-items.md says how to choose them.", ran.stdout)
|
||||
|
||||
def test_refuses_anchors_it_cannot_read(self):
|
||||
(self.checkout / "docs").mkdir()
|
||||
(self.checkout / "docs" / "score-anchors.md").write_text(ANCHORS + "| L 9 | 4 |\n")
|
||||
ran = self.run_tool()
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("docs/score-anchors.md", ran.stderr)
|
||||
|
||||
def test_takes_each_score_at_the_top_of_its_scale(self):
|
||||
ran = self.run_tool("4", "3", "5", "10")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import typing
|
||||
|
||||
from failure import Failure
|
||||
|
||||
# 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 anchors each level.
|
||||
# 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
|
||||
LEVELS = {"L": 4, "E": 3, "I": 5}
|
||||
# The least R each impact level I allows, since a severe enough consequence outranks how unlikely it is.
|
||||
|
||||
Reference in New Issue
Block a user