diff --git a/.gitignore b/.gitignore index 54c35ce5..5c4daffa 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ !bin/loop_claude/ !bin/loop_claude/**/ !bin/loop_claude/**/*.py -!bin/markdown_sections.py +!bin/markdown_text.py !bin/metric-bench !bin/metric_bench/ !bin/metric_bench/*.py @@ -43,6 +43,7 @@ !bin/statusline.py !bin/test_*.py !bin/todo_table.py +!bin/utc_stamp.py !bin/transcript_archive/ !bin/transcript_archive/*.py !docs/ diff --git a/bin/comprehension_history.py b/bin/comprehension_history.py index a9297da2..b7460c44 100644 --- a/bin/comprehension_history.py +++ b/bin/comprehension_history.py @@ -1,10 +1,10 @@ import dataclasses import decimal import re -import time from failure import Failure -from markdown_sections import sections +from markdown_text import sections +from utc_stamp import utc ARCHITECT = "Inherited architect" DECIDED_BY = "decided by" @@ -22,7 +22,6 @@ RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M) RULED_PLACES = re.compile(rf"^.+, {DECIDED_BY}:$") SCORED_PLACES = re.compile(rf"^.+, ({HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$") SENIOR = "Maintainability senior" -STAMP = "%Y-%m-%dT%H:%M:%SZ" TITLE = "# Comprehension history\n" @@ -135,7 +134,7 @@ def bullet_places(bullet: str) -> list[Place]: def heading(at: float, read: str, paired: bool) -> Heading | Failure: """An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read.""" - title = f"{time.strftime(STAMP, time.gmtime(at))}, {read}" + title = f"{utc(at)}, {read}" if (named := HEADING.match(title)) and bool(named.group(4)) == paired: return Heading(title, named.group(2), named.group(3), named.group(4)) return Failure(f"the seats file's first line is not ` at {', against ' if paired else ''}`: {read}") diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index ac449e94..b7f302e5 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -19,10 +19,10 @@ history, or whose last added paired ruling, by heading time, is better; a merge one change against its first parent. With none, the base is the one the history's first paired ruling names; with no ruling either, it is the merge base of HEAD and the default branch. -round-count prints each pass's count: the highest among the titles opening `Answer round -:`, in any case, of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds, -and each name in such a title that is not a pass. It only reports: larv-review asks the human in -place of a further round. +round-count prints each pass's count from the titles, ignoring case, of commits the default branch +does not hold that open `Answer round :`: the highest , or the number of such commits +where that is more. It marks each pass at the cap of {cap} rounds, telling you to ask the human +before another round, and each name in such a title that is not a pass. needs-scoring-run takes the IDs of the todo.md items the chunk ships, none when it ships none, and prints why the chunk is due a scoring run, or `No scoring run due.` It is due when the chunk ships @@ -78,25 +78,21 @@ when the history already holds an entry on what that line reads. Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot -fetch origin for ruling-base or needs-scoring-run, or cannot read or write the history or todo.md. +fetch origin for ruling-base, needs-scoring-run or record-scoring, or cannot read or write the history or todo.md. """ import pathlib import re import sys -import time import typing -from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, scoring_entry, ScoringRun, vote_text from larv_review.ruling_base import base from larv_review.rounds import CAP, PASSES, round_counts -from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top -from larv_review.ruling import counted, fallen, overall, ruling, split, votes +from larv_review.git import default_branch, file_at, git, history_changes from failure import Failure -from larv_review.scoring import fall_ruling, FLOOR, means, under_floor -from todo_table import items, ITEMS_HEADER -from file_writes import replace_file -from larv_review.seats import scores, seats_file, SeatsFile -from larv_review.plan import scoring_run_due +from larv_review.scoring import FLOOR +from comprehension_history import HISTORY +from larv_review.plan import plan_reasons +from larv_review.record import record_ruling, record_scoring USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [...] | record-ruling [] | record-scoring [...]" @@ -164,7 +160,7 @@ def round_count(default: str) -> Failure | None: if isinstance(titles, Failure): return titles for name, count in round_counts(titles.splitlines()).items(): - print(f"{name}: {count}{', at the cap' if count >= CAP else ''}{'' if name in PASSES else ', not a pass: check the commit title'}") + print(f"{name}: {count}{', at the cap: ask the human before another round' if count >= CAP else ''}{'' if name in PASSES else ', not a pass: check the commit title'}") return None @@ -174,152 +170,3 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: return reasons print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") return None - - -def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure: - """Why the plan calls a scoring run, from the default branch's todo.md and the checkout's.""" - checkout = top() - if isinstance(checkout, Failure): - return checkout - before = file_at(default, "todo.md") - if isinstance(before, Failure): - return before - try: - after = pathlib.Path(checkout, "todo.md").read_text(encoding="utf-8") - except (OSError, UnicodeDecodeError) as failure: - return Failure(f"could not read todo.md: {failure}") - # While a chunk reshapes todo.md into one table, the default branch's todo.md has no items table. - planned = items(before) if ITEMS_HEADER in before.splitlines() else [] - if isinstance(planned, Failure): - return Failure(f"{default}'s todo.md: {planned.reason}") - chunk = items(after) - if isinstance(chunk, Failure): - return Failure(f"the checkout's todo.md: {chunk.reason}") - landed = landed_since_release(default) - if isinstance(landed, Failure): - return landed - return scoring_run_due(planned, chunk, ids, landed) - - -def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None: - read = read_seats(votes_file, paired=True) - if isinstance(read, Failure): - return read - heading_read, seats_read = read - written = votes(seats_read.seats) - if isinstance(written, Failure): - return written - counts = counted(seats_read.seats, written) - tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], overall(written[seat.name]), overall(counts[seat.name]))}" for seat in seats_read.seats) - overall_votes = [overall(each) for each in counts.values()] - if split(overall_votes): - print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.") - return None - ruled = ruling(overall_votes) - fell = fallen(counts) if ruled != "worse" else [] - if not fell: - if scores_file: - return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file") - return recorded_ruling(heading_read, seats_read, written, counts, ruled, tally, [], None) - if not scores_file: - print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {heading_read.label} at {heading_read.commit}, write their lines to a scores file, and run this again with both files.") - return None - scoring = read_fall_scores(scores_file, heading_read) - if isinstance(scoring, Failure): - return scoring - ruled, why = fall_ruling(ruled, fell, scoring.means) - return recorded_ruling(heading_read, seats_read, written, counts, ruled, tally, [why], scoring) - - -def recorded_ruling(heading_read: Heading, seats_read: SeatsFile, written: dict[str, list[str]], counts: dict[str, list[str]], ruled: str, tally: str, notes: list[str], scoring: ScoringRun | None) -> Failure | None: - print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}") - return append(seats_read.read, ruling_entry(heading_read.title, seats_read.seats, written, counts, ruled, notes, scoring)) - - -def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None: - read = read_seats(scores_file, paired=False) - if isinstance(read, Failure): - return read - named, given = read - scoring = scored_seats(given) - if isinstance(scoring, Failure): - return scoring - reasons = plan_reasons(default, ids) - if isinstance(reasons, Failure): - return reasons - if not reasons: - return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them, or record a fall's scores with record-ruling") - print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, scoring.means))}.") - if under := under_floor(scoring.means): - print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}.") - return append(given.read, scoring_entry(named.title, scoring)) - - -def read_fall_scores(scores_file: pathlib.Path, votes: Heading) -> ScoringRun | Failure: - """The scores a fall called, once their file names what the votes file read.""" - read = read_seats(scores_file, paired=False, fresh=False) - if isinstance(read, Failure): - return read - named, given = read - if (named.label, named.commit) != (votes.label, votes.commit): - return Failure(f"the scores file's first line is not `{votes.label} at {votes.commit}`, as the votes file reads: {given.read}") - return scored_seats(given) - - -def scored_seats(given: SeatsFile) -> ScoringRun | Failure: - found = scores(given.seats) - if isinstance(found, Failure): - return found - return ScoringRun(given.seats, found, means(list(found.values()))) - - -def read_seats(path: pathlib.Path, paired: bool, fresh: bool = True) -> tuple[Heading, SeatsFile] | Failure: - """The seats file, and the heading its record goes under, once each commit it names is in the checkout and, when fresh, before anything is printed, once the history holds no entry on what it reads.""" - try: - given = seats_file(path.read_text(encoding="utf-8")) - except (OSError, UnicodeDecodeError) as failure: - return Failure(f"could not read {path}: {failure}") - if isinstance(given, Failure): - return given - named = heading(time.time(), given.read, paired) - if isinstance(named, Failure): - return named - if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]: - return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout") - if fresh: - history = history_file() - if isinstance(history, Failure): - return history - if recorded(history[1], given.read): - return Failure(f"{history[0]} already holds an entry on {given.read}; record each ruling or run once") - return named, given - - -def history_file() -> tuple[pathlib.Path, str] | Failure: - """The checkout's history and its text, empty when the file is missing.""" - checkout = top() - if isinstance(checkout, Failure): - return checkout - history = pathlib.Path(checkout, HISTORY) - try: - return history, history.read_text(encoding="utf-8") if history.exists() else "" - except (OSError, UnicodeDecodeError) as failure: - return Failure(f"could not read {history}: {failure}") - - -def append(read: str, entry: str) -> Failure | None: - """Append entry unless the history already holds one on what the seats read.""" - read_history = history_file() - if isinstance(read_history, Failure): - return read_history - history, text = read_history - if recorded(text, read): - return Failure(f"{history} already holds an entry on {read}; record each ruling or run once") - try: - history.parent.mkdir(parents=True, exist_ok=True) - except OSError as failure: - return Failure(f"could not create {history.parent}: {failure}") - if unwritten := replace_file(history, appended(text, entry).encode()): - return Failure(f"could not write {history}: {unwritten.reason}") - print(f"Appended to {history}.") - return None diff --git a/bin/larv_review/plan.py b/bin/larv_review/plan.py index 6254ac31..1e5ec13f 100644 --- a/bin/larv_review/plan.py +++ b/bin/larv_review/plan.py @@ -1,5 +1,8 @@ +import pathlib + from failure import Failure -from todo_table import Item +from larv_review.git import file_at, landed_since_release, top +from todo_table import Item, items, ITEMS_HEADER def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure: @@ -24,3 +27,28 @@ def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[ named = {item.release for item in before + shipped} left = {item.release for item in after if item.id not in {ship.id for ship in shipped}} return sorted(named - left) + + +def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure: + """Why the plan calls a scoring run, from the default branch's todo.md and the checkout's.""" + checkout = top() + if isinstance(checkout, Failure): + return checkout + before = file_at(default, "todo.md") + if isinstance(before, Failure): + return before + try: + after = pathlib.Path(checkout, "todo.md").read_text(encoding="utf-8") + except (OSError, UnicodeDecodeError) as failure: + return Failure(f"could not read todo.md: {failure}") + # While a chunk reshapes todo.md into one table, the default branch's todo.md has no items table. + planned = items(before) if ITEMS_HEADER in before.splitlines() else [] + if isinstance(planned, Failure): + return Failure(f"{default}'s todo.md: {planned.reason}") + chunk = items(after) + if isinstance(chunk, Failure): + return Failure(f"the checkout's todo.md: {chunk.reason}") + landed = landed_since_release(default) + if isinstance(landed, Failure): + return landed + return scoring_run_due(planned, chunk, ids, landed) diff --git a/bin/larv_review/record.py b/bin/larv_review/record.py new file mode 100644 index 00000000..101b1c54 --- /dev/null +++ b/bin/larv_review/record.py @@ -0,0 +1,134 @@ +import pathlib +import time + +from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, scoring_entry, ScoringRun, vote_text +from larv_review.git import commit_exists, top +from larv_review.ruling import counted, fallen, overall, ruling, split, votes +from failure import Failure +from larv_review.scoring import fall_ruling, FLOOR, means, under_floor +from larv_review.plan import plan_reasons +from file_writes import replace_file +from larv_review.seats import scores, seats_file, SeatsFile + + +def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None: + read = read_seats(votes_file, paired=True) + if isinstance(read, Failure): + return read + heading_read, seats_read = read + written = votes(seats_read.seats) + if isinstance(written, Failure): + return written + counts = counted(seats_read.seats, written) + tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], overall(written[seat.name]), overall(counts[seat.name]))}" for seat in seats_read.seats) + overall_votes = [overall(each) for each in counts.values()] + if split(overall_votes): + print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.") + return None + ruled = ruling(overall_votes) + fell = fallen(counts) if ruled != "worse" else [] + scoring = None + notes = [] + if not fell and scores_file: + return Failure("a worse ruling takes no scores file" if ruled == "worse" else f"no dimension fell in this {ruled} ruling, so it takes no scores file") + if fell and not scores_file: + print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {heading_read.label} at {heading_read.commit}, write their lines to a scores file, and run this again with both files.") + return None + if fell and scores_file: + scored = read_fall_scores(scores_file, heading_read) + if isinstance(scored, Failure): + return scored + scoring = scored + ruled, why = fall_ruling(ruled, fell, scoring.means) + notes = [why] + print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}") + return append(seats_read.read, ruling_entry(heading_read.title, seats_read.seats, written, counts, ruled, notes, scoring)) + + +def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None: + read = read_seats(scores_file, paired=False) + if isinstance(read, Failure): + return read + named, given = read + scoring = scored_seats(given) + if isinstance(scoring, Failure): + return scoring + reasons = plan_reasons(default, ids) + if isinstance(reasons, Failure): + return reasons + if not reasons: + return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them, or record a fall's scores with record-ruling") + print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, scoring.means))}.") + if under := under_floor(scoring.means): + print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}.") + return append(given.read, scoring_entry(named.title, scoring)) + + +def read_fall_scores(scores_file: pathlib.Path, votes: Heading) -> ScoringRun | Failure: + """The scores a fall called, once their file names what the votes file read.""" + read = read_seats(scores_file, paired=False, refuse_recorded=False) + if isinstance(read, Failure): + return read + named, given = read + if (named.label, named.commit) != (votes.label, votes.commit): + return Failure(f"the scores file's first line is not `{votes.label} at {votes.commit}`, as the votes file reads: {given.read}") + return scored_seats(given) + + +def scored_seats(given: SeatsFile) -> ScoringRun | Failure: + found = scores(given.seats) + if isinstance(found, Failure): + return found + return ScoringRun(given.seats, found, means(list(found.values()))) + + +def read_seats(path: pathlib.Path, paired: bool, refuse_recorded: bool = True) -> tuple[Heading, SeatsFile] | Failure: + """The seats file, and the heading its record goes under, once each commit it names is in the checkout and, when refuse_recorded, before anything is printed, once the history holds no entry on what it reads.""" + try: + given = seats_file(path.read_text(encoding="utf-8")) + except (OSError, UnicodeDecodeError) as failure: + return Failure(f"could not read {path}: {failure}") + if isinstance(given, Failure): + return given + named = heading(time.time(), given.read, paired) + if isinstance(named, Failure): + return named + if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]: + return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout") + if refuse_recorded: + history = history_file() + if isinstance(history, Failure): + return history + if recorded(history[1], given.read): + return Failure(f"{history[0]} already holds an entry on {given.read}; record each ruling or run once") + return named, given + + +def history_file() -> tuple[pathlib.Path, str] | Failure: + """The checkout's history and its text, empty when the file is missing.""" + checkout = top() + if isinstance(checkout, Failure): + return checkout + history = pathlib.Path(checkout, HISTORY) + try: + return history, history.read_text(encoding="utf-8") if history.exists() else "" + except (OSError, UnicodeDecodeError) as failure: + return Failure(f"could not read {history}: {failure}") + + +def append(read: str, entry: str) -> Failure | None: + """Append entry unless the history already holds one on what the seats read.""" + read_history = history_file() + if isinstance(read_history, Failure): + return read_history + history, text = read_history + if recorded(text, read): + return Failure(f"{history} already holds an entry on {read}; record each ruling or run once") + try: + history.parent.mkdir(parents=True, exist_ok=True) + except OSError as failure: + return Failure(f"could not create {history.parent}: {failure}") + if unwritten := replace_file(history, appended(text, entry).encode()): + return Failure(f"could not write {history}: {unwritten.reason}") + print(f"Appended to {history}.") + return None diff --git a/bin/larv_review/rounds.py b/bin/larv_review/rounds.py index 2b68873b..95e7a0bb 100644 --- a/bin/larv_review/rounds.py +++ b/bin/larv_review/rounds.py @@ -6,10 +6,12 @@ ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) def round_counts(titles: list[str]) -> dict[str, int]: - """Each pass's highest round among the branch's `Answer round :` commit titles; a pass with none has 0, and a title naming no known pass adds its name. Case is ignored, so a mis-cased title still counts.""" - counts = dict.fromkeys(PASSES, 0) + """Each pass's round count among the branch's `Answer round :` commit titles: the highest , or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored, so a mis-cased title still counts.""" + highest: dict[str, int] = dict.fromkeys(PASSES, 0) + commits: dict[str, int] = dict.fromkeys(PASSES, 0) for title in titles: if named := ROUND.match(title): name = named.group(1).lower() - counts[name] = max(counts.get(name, 0), int(named.group(2))) - return counts + highest[name] = max(highest.get(name, 0), int(named.group(2))) + commits[name] = commits.get(name, 0) + 1 + return {name: max(highest[name], commits[name]) for name in highest} diff --git a/bin/larv_review/ruling.py b/bin/larv_review/ruling.py index eb21b881..a8604387 100644 --- a/bin/larv_review/ruling.py +++ b/bin/larv_review/ruling.py @@ -45,7 +45,7 @@ def place_dimensions(place: str) -> list[str]: def split(overall: list[str]) -> bool: - """Whether only the first two seats voted overall and they differ, so two more must vote.""" + """Whether only the first two seats voted overall and they differ, so two more must vote: two votes that differ cannot reach a lead of two.""" return len(overall) == 2 and overall[0] != overall[1] diff --git a/bin/larv_review/scoring.py b/bin/larv_review/scoring.py index d472dfc5..19b86fcd 100644 --- a/bin/larv_review/scoring.py +++ b/bin/larv_review/scoring.py @@ -6,7 +6,7 @@ FLOOR = decimal.Decimal("7.0") def fall_ruling(ruled: str, fell: list[str], found: list[decimal.Decimal]) -> tuple[str, str]: - """The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor.""" + """The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor, so a chunk cannot trade one dimension below the floor for gains in the others.""" if under := [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]: return "worse", f"Fell: {', '.join(fell)}. Under the floor of {FLOOR}: {', '.join(under)}, so the {ruled} ruling counts as worse." return ruled, f"Fell: {', '.join(fell)}, each at or above the floor of {FLOOR}, so the {ruled} ruling stands." diff --git a/bin/larv_review/test_larv_review.py b/bin/larv_review/test_larv_review.py index 839d10f7..22a55426 100644 --- a/bin/larv_review/test_larv_review.py +++ b/bin/larv_review/test_larv_review.py @@ -11,6 +11,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from comprehension_history import appended, entries, HistoryChange, Place, recorded, ruling_entry, ScoringRun, Seat from larv_review.ruling_base import base, first_ruling, measured_commit +import comprehension_history from larv_review.ruling import counted, fallen, ruling, split, votes from failure import Failure from larv_review.scoring import fall_ruling, means, under_floor @@ -113,6 +114,14 @@ class Seats(unittest.TestCase): class History(unittest.TestCase): + def test_writes_the_sample_entry_its_parser_shows(self): + source = pathlib.Path(comprehension_history.__file__).read_text(encoding="utf-8").splitlines() + start = next(index for index, line in enumerate(source) if line.startswith("# ## ")) + sample = [line.removeprefix("#").removeprefix(" ") for line in source[start:] if line.startswith("#")] + seat = Seat("Mid A", said("better", "worse"), ["Locality: `bin/x.py:12` `run`: three branches to hold at once"]) + votes = {"Mid A": ["better", "worse", "same", "same", "better"]} + self.assertEqual(ruling_entry("2026-10-09T09:47:25Z, PR #232 at 324d650, against 12d6d75", [seat], votes, votes, "same", [], None), "\n".join(sample) + "\n") + def test_reads_back_what_it_writes(self): seats = [Seat("Mid A", said("better", "worse"), ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", said("worse", "worse"), [])] written = {"Mid A": ["same", "worse", "same", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "worse"]} @@ -172,6 +181,9 @@ class Rounds(unittest.TestCase): def test_counts_a_mis_cased_title_under_its_pass(self): self.assertEqual(round_counts(["Answer Architecture round 4: x", "Answer architecture round 3: y"])["architecture"], 4) + def test_counts_a_repeated_round_number_as_a_round_of_its_own(self): + self.assertEqual(round_counts(["Answer stability round 3: x", "Answer stability round 3: y", "Answer stability round 2: z", "Answer stability round 1: w"])["stability"], 4) + class ScoringRunDue(unittest.TestCase): def test_reads_each_rows_id_release_and_tagline(self): @@ -255,7 +267,7 @@ class LarvReviewTool(unittest.TestCase): self.commit("Answer prose round 1: c") self.commit("Answer stability round 3: d") ran = self.run_tool("round-count") - self.assertIn("stability: 3, at the cap\n", ran.stdout) + self.assertIn("stability: 3, at the cap: ask the human before another round\n", ran.stdout) self.assertIn("prose: 1\n", ran.stdout) self.assertIn("architecture: 0\n", ran.stdout) diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index 14859400..a6462101 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -1,4 +1,5 @@ from loop_claude.project.records import HUMAN_RULES, RECORD_FILES +from markdown_text import quoted # Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises. QUOTE_SOURCES = "README.md's Goals and Audience, " + ", ".join(RECORD_FILES) + " or " + HUMAN_RULES @@ -23,8 +24,3 @@ def answered(question: str, answer: str) -> str: def past_the_cap(question: str, answer: str, cap: int) -> str: """The question a quoted answer puts to the human once the cycle's quoted answers reach the cap.""" return f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThose files have answered {cap} questions this cycle, the most allowed, so this one comes to you." - - -# Blockquoted, so a passage holding blank lines still ends visibly where the text after it starts. -def quoted(passage: str) -> str: - return "\n".join(f"> {line}" for line in passage.splitlines()) diff --git a/bin/loop_claude/project/premises.py b/bin/loop_claude/project/premises.py index a571227f..1a1a1122 100644 --- a/bin/loop_claude/project/premises.py +++ b/bin/loop_claude/project/premises.py @@ -1,5 +1,5 @@ from loop_claude.project.text_file import read_utf8 -from markdown_sections import sections +from markdown_text import sections from loop_claude.stop import Stop diff --git a/bin/markdown_sections.py b/bin/markdown_text.py similarity index 80% rename from bin/markdown_sections.py rename to bin/markdown_text.py index 593d6655..fa01e7e7 100644 --- a/bin/markdown_sections.py +++ b/bin/markdown_text.py @@ -25,3 +25,8 @@ def sections(text: str) -> dict[str, list[str]]: if name is not None: found.setdefault(name, []).append("\n".join(body)) return found + + +# Blockquoted, so a passage holding blank lines still ends visibly where the text after it starts. +def quoted(passage: str) -> str: + return "\n".join(f"> {line}" for line in passage.splitlines()) diff --git a/bin/rank_todo.py b/bin/rank_todo.py index 7d2835c0..8cf636f7 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -59,7 +59,7 @@ import sys from todo_table import cells, Item, ITEMS_HEADER, parse_row, table_rows from failure import Failure -from markdown_sections import FENCE, sections +from markdown_text import FENCE, sections from file_writes import replace_file LARGEST_FORMULA = 200 diff --git a/bin/reading_cost/figures.py b/bin/reading_cost/figures.py index aa558384..1fc330e1 100644 --- a/bin/reading_cost/figures.py +++ b/bin/reading_cost/figures.py @@ -5,8 +5,8 @@ import statistics from failure import Failure from transcript_archive.read import FinishedChunk from reading_cost.measure import Reading -from markdown_sections import sections -from transcript_archive.outcomes import STAMPED +from markdown_text import sections +from utc_stamp import STAMPED FIGURE = re.compile(rf"^Reading cost, chunk (\w+), finished ({STAMPED})$") FIGURE_PLACE = re.compile(r"^- `(.+)` (\d+)$") diff --git a/bin/reading_cost/main.py b/bin/reading_cost/main.py index b7a1ff13..2dbfc044 100644 --- a/bin/reading_cost/main.py +++ b/bin/reading_cost/main.py @@ -35,7 +35,7 @@ from reading_cost.figures import figure, merged, readings_of, RESET, trend, unhe from transcript_archive.read import finished_chunks, read_threads from transcript_archive.location import project_archive from file_writes import replace_file -from transcript_archive.outcomes import utc +from utc_stamp import utc @dataclasses.dataclass(frozen=True) class Updated: diff --git a/bin/repo_checks/test_types.py b/bin/repo_checks/test_types.py index 525b27ae..7016574f 100644 --- a/bin/repo_checks/test_types.py +++ b/bin/repo_checks/test_types.py @@ -15,5 +15,5 @@ class Types(unittest.TestCase): self.assertIsNotNone(floor, "README.md's Install names `Python 3.N or newer`") if shutil.which("uv") is None: self.fail("uv on PATH fetches mypy; see README.md's Test line") - ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "--exclude", "/test_", "-p", "claude_code", "-m", "comprehension_history", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "project_key", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline", "-m", "todo_table", "-p", "transcript_archive"], capture_output=True, cwd=ROOT / "bin", text=True) + ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "--exclude", "/test_", "-p", "claude_code", "-m", "comprehension_history", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "project_key", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline", "-m", "todo_table", "-m", "utc_stamp", "-m", "markdown_text", "-p", "transcript_archive"], capture_output=True, cwd=ROOT / "bin", text=True) self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) diff --git a/bin/test_markdown_sections.py b/bin/test_markdown_text.py similarity index 52% rename from bin/test_markdown_sections.py rename to bin/test_markdown_text.py index 3f5aa545..f069da32 100644 --- a/bin/test_markdown_sections.py +++ b/bin/test_markdown_text.py @@ -4,18 +4,21 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -import markdown_sections +import markdown_text class Sections(unittest.TestCase): def test_keeps_every_headed_section_with_its_bodies(self): text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n" - self.assertEqual(markdown_sections.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) + self.assertEqual(markdown_text.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) def test_closes_a_fence_only_on_its_own_marker(self): text = "## Goals\n````md\n~~~\n## Quoted\n```\n````\n ~~~\n## Also quoted\n ~~~\n1. one\n## Audience\nme\n" - self.assertEqual(list(markdown_sections.sections(text)), ["Goals", "Audience"]) - self.assertEqual(list(markdown_sections.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) + self.assertEqual(list(markdown_text.sections(text)), ["Goals", "Audience"]) + self.assertEqual(list(markdown_text.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) + + def test_quotes_every_line_of_a_passage_blank_ones_included(self): + self.assertEqual(markdown_text.quoted("merged\n\nPR #1"), "> merged\n> \n> PR #1") if __name__ == "__main__": diff --git a/bin/transcript_archive/outcomes.py b/bin/transcript_archive/outcomes.py index e4810f10..8d7b76ff 100644 --- a/bin/transcript_archive/outcomes.py +++ b/bin/transcript_archive/outcomes.py @@ -1,9 +1,9 @@ import re -import time + +from markdown_text import quoted +from utc_stamp import STAMPED FINISHED = "Verdict: finished" -STAMP = "%Y-%m-%dT%H:%M:%SZ" -STAMPED = r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ" FINISHED_AT = re.compile(rf"^({STAMPED}) {re.escape(FINISHED)}$", re.MULTILINE) @@ -25,12 +25,3 @@ def answered(question: str, sources: str, answer: str, evidence: str) -> str: def stopped(why: str) -> str: return f"Stopped: {why}" - - -# Blockquoted, so evidence holding blank lines still ends visibly where the text after it starts. -def quoted(passage: str) -> str: - return "\n".join(f"> {line}" for line in passage.splitlines()) - - -def utc(at: float) -> str: - return time.strftime(STAMP, time.gmtime(at)) diff --git a/bin/transcript_archive/test_transcript_archive.py b/bin/transcript_archive/test_transcript_archive.py index 7301ebdd..401aa0c0 100644 --- a/bin/transcript_archive/test_transcript_archive.py +++ b/bin/transcript_archive/test_transcript_archive.py @@ -11,6 +11,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from transcript_archive import outcomes, write from transcript_archive.location import project_archive from project_key import project_key +from utc_stamp import utc NOW = 1790000000 @@ -43,10 +44,7 @@ class CopyFor(unittest.TestCase): class Outcomes(unittest.TestCase): def test_the_archive_stamps_what_it_reads_back(self): - self.assertRegex(f"{outcomes.utc(NOW)} {outcomes.finished('merged')}", outcomes.FINISHED_AT) - - def test_quotes_every_line_of_a_passage_blank_ones_included(self): - self.assertEqual(outcomes.quoted("merged\n\nPR #1"), "> merged\n> \n> PR #1") + self.assertRegex(f"{utc(NOW)} {outcomes.finished('merged')}", outcomes.FINISHED_AT) class Location(unittest.TestCase): diff --git a/bin/transcript_archive/write.py b/bin/transcript_archive/write.py index 0fddd021..4d01604e 100644 --- a/bin/transcript_archive/write.py +++ b/bin/transcript_archive/write.py @@ -7,7 +7,7 @@ from failure import Failure from claude_code.transcript import first_timestamped_line from file_writes import make_private, replace_file from claude_code.session import session_files -from transcript_archive.outcomes import utc +from utc_stamp import utc # //.jsonl, its .outcomes.md beside it, and the session's other files under /session/ diff --git a/bin/utc_stamp.py b/bin/utc_stamp.py new file mode 100644 index 00000000..17542bc9 --- /dev/null +++ b/bin/utc_stamp.py @@ -0,0 +1,8 @@ +import time + +STAMP = "%Y-%m-%dT%H:%M:%SZ" +STAMPED = r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ" + + +def utc(at: float) -> str: + return time.strftime(STAMP, time.gmtime(at))