From 1e5c01eb820751fc2d3376a6c93f16a172d6c290 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:37:22 +0100 Subject: [PATCH 01/10] Append the reading-cost figure --- docs/reading-cost.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 191576fb..2512c54f 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -1347,3 +1347,17 @@ Read most (opens and searches): - `bin/judge_replay/main.py` 3 - `bin/review_replay/test_review_replay.py` 3 - `bin/score_outcomes/main.py` 3 + +## Reading cost, chunk 7e1292c4ef5d, finished 2026-11-09T00:31:46Z + +58849 new input tokens before the first commit. + +Read most (opens and searches): + +- `todo.md` 7 +- `skills/larv-review/SKILL.md` 3 +- `AGENTS.md` 2 +- `CHANGELOG.md` 2 +- `CLAUDE.md` 2 +- `docs/decisions.md` 2 +- `README.md` 1 -- 2.52.0 From c47d65996ec17e3999fb4811d6e2704da8706441 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:37:22 +0100 Subject: [PATCH 02/10] File and finish todo.md items with todo-item add and todo-item finish --- CHANGELOG.md | 2 ++ CLAUDE.md | 2 +- README.md | 3 ++- rules/todo-items.md | 1 + todo.md | 10 ---------- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35e76bf9..4d614cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- `todo-item add` now files an item in `todo.md` with one command. It gives the item `Next ID`, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file. +- `todo-item finish ` now removes a finished item from `todo.md`, its row and its detail, and adds its bullet first under `CHANGELOG.md` → `## Unreleased`. Where a `CHANGELOG.md` exists, it asks for `--changelog ` or `--no-changelog`, so no bullet is left out by mistake. - A worker whose review rules its work below standard now fixes it on its own rung where the fix changes only prose, a comment or docstring included. It hands the fix to a higher rung only where code, config or tests change. - `loop-claude`'s judge now sends a question you answered earlier in the chunk back to the worker, quoting your answer, unless the question ends with the words of your answer that leave it open. You are asked only about what your answer left open. - `score-outcomes` now shows, beside what each finished item's chunk measured, the size of the files and folders its tagline or detail names in backticks: how many files, and how many lines, as they stood before its chunk. diff --git a/CLAUDE.md b/CLAUDE.md index c9703d80..66461aa3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,7 +15,7 @@ How work proceeds in any repo, unless the repo's `AGENTS.md` says otherwise. The - **Ask, don't guess.** Three choices are always the human's: a goal; a release, meaning the items planned into it and when it is cut; and a change to loop-claude's routing ladder, its rungs included. Any other rule that asks the human's approval reserves that choice too. Ask about a reserved choice. For any other choice, first check whether the goals already answer it. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Otherwise take the option you would recommend, and record it with its reason: in the item's detail, or, where it governs later work, as the next sentence says. A recommendation you can give a reason for is not a guess. Ask only where you have no recommendation. Write every answer once, where it belongs, never only in chat: a goal in `README.md`, a working rule in `AGENTS.md`, a standing choice in a comment at the one place it governs, or in `docs/decisions.md` once made in more than one place. When an answer holds a goal and a choice, write the goal in the README, and record as a choice only what the goal leaves open. - **Bench a syntax with the people who write it.** Before a new or changed spelling of something users read or write ships — markdown, HTML, a config key, a CLI flag — a panel of fresh-context readers, seated as those users from the README's `## Audience`, picks it. - **Implement the simplest change that solves the item, and ship it with `/larv-review`.** Whenever a test can check the change, write that test first and see it fail. Take its expected values from the item, never from the code. larv-review's reviewers hold the change to the technical principles, and a finding against one names it. Read a file under `~/.claude/principles/` only when the item changes it, a finding or a record you write names it, or you decline a finding. -- **Remove a finished item's row and detail from `todo.md`, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. +- **Remove a finished item's row and detail from `todo.md`, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish `, with `--changelog ` or `--no-changelog`, does both. - **Releases are the human's.** The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision. - **Open each `todo.md` item or ticket with a bold one-sentence tagline**, so the taglines alone say what a release holds. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and says nothing about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: `**Accept undefined in MetadataValue and drop such keys on output.**` BANNED: `MetadataValue accepts undefined; such keys are dropped on output`. - **File a security finding the moment it is found.** A security finding — a leaked credential, secret or PII, an auth bypass, an injection — goes under the next release, marked `security`, naming the exposure and the path it reaches. `~/.claude/bin/rank_todo.py` ranks it first in its release, after only the open questions, which wait for me. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will unmark it if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius. diff --git a/README.md b/README.md index 371d22e0..7fb3e75a 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it. - `subagent-rung [--plan] ` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule. +- `todo-item add …` files an item in a project's `todo.md` under its `Next ID`, and `todo-item finish ` removes a finished one and adds its bullet to `CHANGELOG.md`; both rank the file, and `todo-item --help` states the flags. Test on the host with `uvx --python "$(command -v python3)" --with pytest-xdist==3.8.0 pytest==9.2.0 -n 4 bin`. It needs `uv` on `PATH`, which fetches pytest, pytest-xdist and mypy. pytest-xdist runs the tests in four workers, one heavy slot's CPUs (`docs/decisions.md` → `bin/: the tools support only the latest stable Python, …`). `python3 -m unittest discover -s bin -p 'test_*.py'` runs the same tests one at a time. Test the bench's scripts with `python3 -m unittest discover -s workflow-bench -p 'test_*.py'`. @@ -138,7 +139,7 @@ Then, in the copy: `uvx --with pytest==9.2.0 'mutmut>=3,<4' run && uvx --with py - `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read. - `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them. - `records/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, stamps times in UTC, and replaces a file in one step, private where it is new. -- `release_plan/` reads `todo.md`'s items table and release versions, says which release is next and whether it is ready to cut (`release_standing.py`), and ranks the plan (`ranking.py`, which `rank_todo.py`, `larv_review` and `rule_hook` import). +- `release_plan/` reads `todo.md`'s items table and release versions, says which release is next and whether it is ready to cut (`release_standing.py`), and ranks the plan (`ranking.py`, which `rank_todo.py`, `todo_item`, `larv_review` and `rule_hook` import). - `repo_checks/` tests the repo itself. - `review_rules/` holds the larv-review rules that several tools apply: its passes, its review folder, its round commit titles and the comprehension history's format. - `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls. diff --git a/rules/todo-items.md b/rules/todo-items.md index 97384830..7a2cdce8 100644 --- a/rules/todo-items.md +++ b/rules/todo-items.md @@ -6,6 +6,7 @@ paths: # Todo items (`todo.md`) - **`todo.md` is mandatory in every project, in the shape `rank_todo.py --help` shows**, which `~/.claude/bin/rank_todo.py` checks and ranks; its `--help` shows a valid file. `## Scoring` holds the formula and the bar; `## Items` is one table of every item; `## Details` holds each item's detail under its ID. `## Renamed` marks each renamed release with a line such as `- 0.2.1 renamed to 0.3.0`; `rank_todo.py --help` says what a mark does. Cite an item by its ID. The formula and bar are the project's own to tune. +- **File an item with `~/.claude/bin/todo-item add`.** It gives the item `Next ID`, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file; `todo-item --help` shows the flags. - **Order items only by score and the Blocked by column.** An item's Blocked by cell lists the IDs of the items that must be done before it starts, such as `12, 14`; `rank_todo.py --help` says how it ranks them. No text in `todo.md` outside the table orders items: where an item must go first, score it so, and say why in its detail. - **Plan only on the project's rung or above.** loop-claude's prompt tells you when you run below it. Below it, never score or re-score an item, move it between releases, split a milestone into items, delete an item under the bar, rewrite a filed item's tagline or detail, or choose or replace an item in `docs/score-anchors.md`. Draft each new item, each change to a filed item, and each change to the anchors, instead. Before your next commit, launch one subagent to apply the drafts, score them and set their release. Launch it on the rung `CLAUDE.md`'s delegation rule gives a subagent that files or scores items. Keep the scores and releases it writes. For a security finding, launch it at once. Any rung may remove a finished item's row and detail, and score a delegated task's L. A subagent launched for another task leaves `todo.md` alone. - **An item's release allows the bump that semver read strictly asks for.** An item that changes what exists needs a major, or before 1.0.0 a minor. One that only adds needs a minor, and a fix a patch. diff --git a/todo.md b/todo.md index f4b9341a..9edaa728 100644 --- a/todo.md +++ b/todo.md @@ -14,12 +14,10 @@ |---|---|---|---|---|---|---|---|---|---|---|---| | 277 | 0.7.0 | | question | **Map the size of the code an item names onto S, on a scale the human picks, and have `score-outcomes` print that S for the item being scored and for each finished item it lists.** | 3 | 2 | 2 | 5 | 4 | 1.1 by 4, 1.4 by 3 | 2.4 | | 1 | 0.7.0 | | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 1 | 2 | 1 | 2 | 1 | | 0.0 | -| 279 | 0.7.0 | | | **Add an item to `todo.md` with one command that reads `Next ID`, bumps it, and inserts the row and its detail.** | 3 | 1 | 3 | 5 | 3 | 1.4 by 3, 1.5 by 3 | 2.3 | | 116 | 0.7.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 2.3 | | 280 | 0.7.0 | | | **Open the chunk's pull request as a draft, mark it ready and merge it with one command per step that picks `tea` or `gh` from the remote, so no worker looks up `tea`'s or `gh`'s flags.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 4, 1.5 by 3 | 2.3 | | 282 | 0.7.0 | | | **Write the branch diff and what `larv-review places` prints into the chunk's review folder, and print each reviewer's prompt header, with one `larv-review` command.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 4, 1.5 by 3 | 2.3 | | 12 | 0.7.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 2.1 | -| 278 | 0.7.0 | | | **Remove a finished item's row and detail from `todo.md` and add its changelog bullet under `## Unreleased` with one command, given the item's ID and the bullet.** | 3 | 1 | 3 | 5 | 3 | 1.4 by 3, 1.5 by 2 | 2.0 | | 285 | 0.7.0 | | | **Cut a worker's opens and searches of `todo.md` from the median 7 per chunk to at most 3, by finding in the last five chunks' archived transcripts what each read was for and removing its cause.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 4 | 1.6 | | 281 | 0.7.0 | | | **Remove a merged chunk's worktree and branch and fast-forward the main checkout with one command.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 2, 1.5 by 2 | 1.6 | | 283 | 0.7.0 | | | **Print, for the archived chunks of a release, a table of its shell command patterns, such as `tea pr create`: the chunks that ran each, its calls, command tokens, result tokens and tool time, so an audit reads one table.** | 3 | 2 | 1 | 4 | 3 | 1.4 by 2, 1.5 by 2 | 1.6 | @@ -79,10 +77,6 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost The README line covers the bench's transcripts in `workflow-bench/logs/` too (goal 3). -### 279. Add an item to `todo.md` with one command that reads `Next ID`, bumps it, and inserts the row and its detail. - -Audit of release 0.2.0's chunks (item 162): 22 chunks filed items with a Python heredoc written by hand, 55 calls, about 11k command tokens and 8 minutes of tool time. The model supplies the tagline, scores and detail; the program allocates the ID, writes the row and the detail in place, and ranks the table with `rank_todo.py`. - ### 116. Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴. `score-outcomes` reports the median 🔴 count at each guessed R, and how well L orders chunks by 🔴 findings; the part of R a 🔴 tests is L. Where most chunks have no 🔴, every median reads 0 and the rank correlation rests on the few that have one, which tells a scorer little. No round title held counts before PR #254, so how often a chunk has a 🔴 is not yet known. @@ -101,10 +95,6 @@ The repo has no CI, so larv-review's gate is the local run, and larv-review's Ga When CI runs a rule check, such as one of `bin/rule-hook`'s, let `` in the PR body override it. -### 278. Remove a finished item's row and detail from `todo.md` and add its changelog bullet under `## Unreleased` with one command, given the item's ID and the bullet. - -Audit of release 0.2.0's chunks (item 162): 16 chunks edited `CHANGELOG.md` and at least 10 deleted an item's row and its `### .` detail from `todo.md`, each time with a Python heredoc written by hand. The CHANGELOG edits alone were 33 calls, about 9k command tokens and 6 minutes of tool time. The program removes the row and the detail, creates `## Unreleased` when it is missing, and inserts the bullet; the bullet's wording stays with the model. - ### 285. Cut a worker's opens and searches of `todo.md` from the median 7 per chunk to at most 3, by finding in the last five chunks' archived transcripts what each read was for and removing its cause. Item 105 compared the five chunks before and after the `worker:` decision, merged 2026-10-13 at 06:49Z in 21b060e, matching chunks to PRs by finish time. Reading cost, the new input tokens before the first commit, rose: median 56,802 before and 136,132 after. The ranges, 46k to 172k and 50k to 140k, overlap. Review rounds per pass did not rise: 2.26 before and 1.52 after, among the five multi-pass chunks on each side. -- 2.52.0 From 0c5ea295f11595c49524f2f4d4ed35ec6add8fc4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:37:52 +0100 Subject: [PATCH 03/10] Track bin/todo-item and its package --- .gitignore | 3 + bin/todo-item | 9 +++ bin/todo_item/__init__.py | 0 bin/todo_item/edits.py | 82 ++++++++++++++++++++++ bin/todo_item/main.py | 114 +++++++++++++++++++++++++++++++ bin/todo_item/test_todo_item.py | 116 ++++++++++++++++++++++++++++++++ 6 files changed, 324 insertions(+) create mode 100755 bin/todo-item create mode 100644 bin/todo_item/__init__.py create mode 100644 bin/todo_item/edits.py create mode 100644 bin/todo_item/main.py create mode 100644 bin/todo_item/test_todo_item.py diff --git a/.gitignore b/.gitignore index e9b0cc50..10bd194b 100644 --- a/.gitignore +++ b/.gitignore @@ -89,6 +89,9 @@ !bin/subagent_rung/ !bin/subagent_rung/*.py !bin/test_*.py +!bin/todo-item +!bin/todo_item/ +!bin/todo_item/*.py !bin/transcript_archive/ !bin/transcript_archive/*.py !docs/ diff --git a/bin/todo-item b/bin/todo-item new file mode 100755 index 00000000..1f73d950 --- /dev/null +++ b/bin/todo-item @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +import pathlib +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) + +from todo_item import main + +sys.exit(main.main(sys.argv[1:])) diff --git a/bin/todo_item/__init__.py b/bin/todo_item/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/todo_item/edits.py b/bin/todo_item/edits.py new file mode 100644 index 00000000..728e8fc9 --- /dev/null +++ b/bin/todo_item/edits.py @@ -0,0 +1,82 @@ +"""The text edits behind todo-item: filing an item in todo.md, removing a finished one, and adding a bullet to CHANGELOG.md. Each returns new text; ranking.rank then orders the table and details and writes the derived cells.""" +import re + +from failure import Failure +from release_plan.ranking import stated +from release_plan.todo_table import cells, DETAILS, items_table, Table + +# A line that would end the item's detail, or open another one, inside ## Details. +HEADING = re.compile(r"^#{1,3} ", re.M) +UNRELEASED = "## Unreleased" + + +def added(todo: str, named: dict[str, str], detail: str) -> tuple[int, str] | Failure: + """todo with an item filed under Next ID, and that ID; named holds its cells by column name, its Item cell a plain tagline.""" + next_id = stated(todo, "Next ID") + if isinstance(next_id, Failure): + return next_id + if not next_id.isdigit(): + return Failure(f"Next ID {next_id!r} is not a whole number") + tagline = named["Item"].strip().removeprefix("**").removesuffix("**") + if "\n" in tagline: + return Failure("the tagline holds a line break; keep it on one line") + if HEADING.search(detail): + return Failure("the detail holds a markdown heading, which would split ## Details; drop the #s") + id_ = int(next_id) + lines = re.sub(r"^`Next ID = [0-9]+`$", f"`Next ID = {id_ + 1}`", todo, count=1, flags=re.M).split("\n") + table = held_table(lines) + if isinstance(table, Failure): + return table + row = {**named, "ID": str(id_), "Item": "**" + re.sub(r"(? str | Failure: + """todo without item id_'s row and its detail.""" + lines = todo.split("\n") + table = held_table(lines) + if isinstance(table, Failure): + return table + for at, row in enumerate(table.rows, table.start): + found = cells(row, len(table.columns)) + if isinstance(found, Failure): + return found + if found[0] == str(id_): + del lines[at] + break + else: + return Failure(f"todo.md holds no item {id_}") + text = "\n".join(lines) + section = DETAILS.search(text) + if section is None: + return text + body = re.sub(rf"^### {id_}\. .*?(?=^### |\Z)", "", section.group(1), count=1, flags=re.M | re.S) + return text[:section.start(1)] + body + text[section.end(1):] + + +def with_bullet(changelog: str, bullet: str) -> str | Failure: + """changelog with bullet first under ## Unreleased, which goes above the first release where missing; a new changelog where changelog is empty.""" + line = "- " + bullet.strip().removeprefix("- ") + if "\n" in line: + return Failure("the changelog bullet holds a line break; keep it on one line") + if not changelog.strip(): + return f"# Changelog\n\n{UNRELEASED}\n\n{line}\n" + if section := re.search(rf"^{UNRELEASED}\n+", changelog, re.M): + rest = changelog[section.end():] + return changelog[:section.end()] + line + "\n" + ("" if rest.startswith("- ") or not rest else "\n") + rest + if release := re.search(r"^## ", changelog, re.M): + return changelog[:release.start()] + f"{UNRELEASED}\n\n{line}\n\n" + changelog[release.start():] + return changelog.rstrip("\n") + f"\n\n{UNRELEASED}\n\n{line}\n" + + +def held_table(lines: list[str]) -> Table | Failure: + table = items_table(lines) + return Failure("todo.md holds no items table; rank_todo.py --help shows one") if table is None else table diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py new file mode 100644 index 00000000..1930ff3f --- /dev/null +++ b/bin/todo_item/main.py @@ -0,0 +1,114 @@ +"""File an item in todo.md, or finish one, and rank the file as rank_todo.py does. + +usage: todo-item add --release --l --e --i --s [--moves ] + [--blocked-by ] [--exempt ] [<<'EOF' detail EOF] + todo-item finish [--changelog | --no-changelog] + +Works on the todo.md in the current folder, and the CHANGELOG.md and docs/decisions.md beside it. +The cells take the format rank_todo.py --help states; the letter flags take upper case too, as --L. + +add takes Next ID as the item's ID and raises Next ID by one. It writes the row, with the tagline +in bold and each | in it escaped, and the detail it reads from stdin, if any, under ## Details. +It prints `Filed item .` It writes nothing where ranking fails or scores the item under the bar. + +finish removes the item's row and its detail. With --changelog it adds the bullet first under +CHANGELOG.md's ## Unreleased, creating the section, or the file, where missing. Where CHANGELOG.md +exists, finish needs --changelog or --no-changelog, so no bullet is left out by mistake. It prints +`Finished item .` It writes nothing while docs/decisions.md cites the item. + +Exit 2 on bad arguments; exit 1, saying why, where it writes nothing. +""" +import argparse +import pathlib +import sys +import typing + +from failure import Failure +from release_plan import ranking +from release_plan.todo_table import BLOCKED_BY, MOVES +from todo_item.edits import added, finished, with_bullet + +# Each score flag, as --l or --L, and the column it fills. +LETTERS = ("L", "E", "I", "S") + + +def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.TextIO = sys.stdin) -> int: + args = parser().parse_args(argv) + done = add(args, folder, stdin) if args.command == "add" else finish(args, folder) + if isinstance(done, Failure): + print(done.reason, file=sys.stderr) + return 1 + print(done) + return 0 + + +def parser() -> argparse.ArgumentParser: + parsed = argparse.ArgumentParser(prog="todo-item", description=__doc__.split("\n\n")[0]) + commands = parsed.add_subparsers(dest="command", required=True) + adding = commands.add_parser("add") + adding.add_argument("--release", required=True) + for letter in LETTERS: + adding.add_argument(f"--{letter.lower()}", f"--{letter}", dest=letter, required=True) + adding.add_argument("--moves", default="") + adding.add_argument("--blocked-by", default="") + adding.add_argument("--exempt", default="") + adding.add_argument("tagline") + finishing = commands.add_parser("finish") + finishing.add_argument("id", type=int) + bullet = finishing.add_mutually_exclusive_group() + bullet.add_argument("--changelog") + bullet.add_argument("--no-changelog", action="store_true") + return parsed + + +def add(args: argparse.Namespace, folder: pathlib.Path, stdin: typing.TextIO) -> str | Failure: + todo = folder / "todo.md" + texts = ranking.read_all(todo) + if isinstance(texts, Failure): + return texts + named = {"Release": args.release, BLOCKED_BY: args.blocked_by, "Exempt": args.exempt, "Item": args.tagline, MOVES: args.moves} + filed = added(texts[0], named | {letter: getattr(args, letter) for letter in LETTERS}, "" if stdin.isatty() else stdin.read()) + if isinstance(filed, Failure): + return Failure(f"not filed: {filed.reason}") + id_, text = filed + ranked = ranking.rank(text, *texts[1:]) + if isinstance(ranked, Failure): + return Failure(f"not filed: {ranked.reason}") + if under := [line for line in ranked.under_bar if line.startswith(f"item {id_} ")]: + return Failure(f"not filed: {under[0]}") + if unwritten := ranking.write(todo, ranked.text): + return unwritten + report(todo, ranked) + return f"Filed item {id_}." + + +def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure: + todo, changelog = folder / "todo.md", folder / "CHANGELOG.md" + if changelog.exists() and args.changelog is None and not args.no_changelog: + return Failure("CHANGELOG.md exists beside todo.md; pass --changelog , or --no-changelog for an item consumers don't notice") + texts = ranking.read_all(todo) + if isinstance(texts, Failure): + return texts + text = finished(texts[0], args.id) + if isinstance(text, Failure): + return text + ranked = ranking.rank(text, *texts[1:]) + if isinstance(ranked, Failure): + return ranked + news = None + if args.changelog is not None: + news = with_bullet(changelog.read_text(encoding="utf-8") if changelog.exists() else "", args.changelog) + if isinstance(news, Failure): + return news + if unwritten := ranking.write(todo, ranked.text): + return unwritten + if news is not None and (unwritten := ranking.write(changelog, news)): + return Failure(f"{unwritten.reason}; todo.md no longer holds item {args.id}, so add its bullet by hand") + report(todo, ranked) + return f"Finished item {args.id}." + + +def report(todo: pathlib.Path, ranked: ranking.Ranked) -> None: + """Print what ranking says beside the ranked file, as rank_todo.py does.""" + for line in ranked.notes + ranked.under_bar: + print(f"{todo}: {line}", file=sys.stderr) diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py new file mode 100644 index 00000000..7cafb0c3 --- /dev/null +++ b/bin/todo_item/test_todo_item.py @@ -0,0 +1,116 @@ +import contextlib +import io +import pathlib +import sys +import tempfile +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) + +from release_plan import ranking +from release_plan.test_ranking import DECISIONS, README, TODO +from todo_item import main + +ADD = ["add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the `a | b` runs."] +ROW = "| 6 | 0.1.0 | | | **Count the `a \\| b` runs.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 |" +CHANGELOG = "# Changelog\n\n## Unreleased\n\n- Older news.\n\n## 0.1.0\n\n- First.\n" + + +class TodoItem(unittest.TestCase): + def setUp(self): + temp = tempfile.TemporaryDirectory() + self.addCleanup(temp.cleanup) + self.folder = pathlib.Path(temp.name) + self.todo = self.folder / "todo.md" + (self.folder / "README.md").write_text(README) + (self.folder / "docs").mkdir() + (self.folder / "docs" / "decisions.md").write_text(DECISIONS) + ranked = ranking.rank(TODO, README, DECISIONS, "") + assert not isinstance(ranked, ranking.Failure) + self.todo.write_text(ranked.text) + + def run_main(self, *argv, stdin=""): + with contextlib.redirect_stdout(io.StringIO()) as out, contextlib.redirect_stderr(io.StringIO()) as err: + code = main.main(list(argv), self.folder, io.StringIO(stdin)) + return code, out.getvalue(), err.getvalue() + + def assert_ranked(self): + self.assertEqual(ranking.check_failures(self.todo), []) + + +class Add(TodoItem): + def test_takes_next_id_bumps_it_and_writes_the_row_and_detail_ranked(self): + self.assertEqual(self.run_main(*ADD, stdin="What the tagline leaves out.\n"), (0, "Filed item 6.\n", "")) + text = self.todo.read_text() + self.assertIn("`Next ID = 7`", text) + self.assertIn(ROW, text) + self.assertIn("### 6. Count the `a | b` runs.\n\nWhat the tagline leaves out.\n", text) + self.assert_ranked() + + def test_files_no_detail_from_empty_stdin_and_takes_upper_case_letters_blockers_and_exempt(self): + argv = ["add", "--release", "0.1.0", "--blocked-by", "2", "--exempt", "owner", "--L", "1", "--E", "1", "--I", "1", "--S", "1", "**Count the runs.**"] + self.assertEqual(self.run_main(*argv)[:2], (0, "Filed item 6.\n")) + text = self.todo.read_text() + self.assertIn("| 6 | 0.1.0 | 2 | owner | **Count the runs.** | 1 | 1 | 1 | 1 | 1 | |", text) + self.assertNotIn("### 6.", text) + self.assert_ranked() + + def test_creates_details_where_todo_has_none(self): + self.todo.write_text(self.todo.read_text().split("## Details")[0].rstrip("\n") + "\n") + self.assertEqual(self.run_main(*ADD, stdin="Detail.")[0], 0) + self.assertTrue(self.todo.read_text().endswith("## Details\n\n### 6. Count the `a | b` runs.\n\nDetail.\n")) + self.assert_ranked() + + def test_writes_nothing_for_an_item_under_the_bar_or_one_ranking_rejects(self): + before = self.todo.read_text() + code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "Count the runs.") + self.assertEqual((code, err), (1, "not filed: item 6 scores 0.0, under the bar 2; delete it, or mark it with a reason the bar does not apply\n")) + code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "9", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the runs.") + self.assertEqual((code, err), (1, "not filed: item 6's L '9' is not a whole number from 1 to 4\n")) + code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count\nthe runs.") + self.assertEqual((code, err), (1, "not filed: the tagline holds a line break; keep it on one line\n")) + self.assertEqual(self.todo.read_text(), before) + + +class Finish(TodoItem): + def test_removes_the_row_and_detail_and_adds_the_bullet_first_under_unreleased(self): + (self.folder / "CHANGELOG.md").write_text(CHANGELOG) + self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, "Finished item 3.\n", "")) + text = self.todo.read_text() + self.assertNotRegex(text, r"(?m)^\| 3 \|") + self.assertNotIn("### 3.", text) + self.assertIn("### 1. Ship the later thing.\n\nLater detail.\n", text) + self.assert_ranked() + self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n- Older news.\n\n## 0.1.0\n\n- First.\n") + + def test_creates_unreleased_or_the_changelog_where_missing(self): + (self.folder / "CHANGELOG.md").write_text("# Changelog\n\n## 0.1.0\n\n- First.\n") + self.assertEqual(self.run_main("finish", "3", "--changelog", "- Runs are fast.")[0], 0) + self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n\n## 0.1.0\n\n- First.\n") + (self.folder / "CHANGELOG.md").unlink() + self.assertEqual(self.run_main("finish", "2", "--changelog", "Tests are tight.")[0], 0) + self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Tests are tight.\n") + + def test_needs_a_changelog_choice_where_a_changelog_exists(self): + (self.folder / "CHANGELOG.md").write_text(CHANGELOG) + before = self.todo.read_text() + code, _, err = self.run_main("finish", "2") + self.assertEqual((code, err), (1, "CHANGELOG.md exists beside todo.md; pass --changelog , or --no-changelog for an item consumers don't notice\n")) + self.assertEqual(self.todo.read_text(), before) + self.assertEqual(self.run_main("finish", "2", "--no-changelog"), (0, "Finished item 2.\n", "")) + self.assertEqual((self.folder / "CHANGELOG.md").read_text(), CHANGELOG) + self.assertNotRegex(self.todo.read_text(), r"(?m)^\| 2 \|") + + def test_writes_nothing_for_an_item_a_decision_cites(self): + before = self.todo.read_text() + code, _, err = self.run_main("finish", "5", "--changelog", "Writes moved out.") + self.assertEqual((code, err), (1, 'docs/decisions.md cites "`todo.md` item 5", which todo.md no longer holds; revise that decision to say what holds now\n')) + self.assertEqual(self.todo.read_text(), before) + self.assertFalse((self.folder / "CHANGELOG.md").exists()) + + def test_fails_on_an_item_the_table_does_not_hold(self): + self.assertEqual(self.run_main("finish", "9", "--no-changelog"), (1, "", "todo.md holds no item 9\n")) + + +if __name__ == "__main__": + unittest.main() -- 2.52.0 From 126b125e9bcbcc0e5a8f77f9c8d964dcc5fb4962 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:39:24 +0100 Subject: [PATCH 04/10] Sort todo_item's imports and narrow the changelog text for mypy --- bin/todo_item/edits.py | 2 +- bin/todo_item/main.py | 13 +++++++------ bin/todo_item/test_todo_item.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/todo_item/edits.py b/bin/todo_item/edits.py index 728e8fc9..802bec79 100644 --- a/bin/todo_item/edits.py +++ b/bin/todo_item/edits.py @@ -1,9 +1,9 @@ """The text edits behind todo-item: filing an item in todo.md, removing a finished one, and adding a bullet to CHANGELOG.md. Each returns new text; ranking.rank then orders the table and details and writes the derived cells.""" import re +from release_plan.todo_table import cells, DETAILS, items_table, Table from failure import Failure from release_plan.ranking import stated -from release_plan.todo_table import cells, DETAILS, items_table, Table # A line that would end the item's detail, or open another one, inside ## Details. HEADING = re.compile(r"^#{1,3} ", re.M) diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index 1930ff3f..2d5527ea 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -23,10 +23,10 @@ import pathlib import sys import typing +from todo_item.edits import added, finished, with_bullet +from release_plan.todo_table import BLOCKED_BY, MOVES from failure import Failure from release_plan import ranking -from release_plan.todo_table import BLOCKED_BY, MOVES -from todo_item.edits import added, finished, with_bullet # Each score flag, as --l or --L, and the column it fills. LETTERS = ("L", "E", "I", "S") @@ -95,11 +95,12 @@ def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure: ranked = ranking.rank(text, *texts[1:]) if isinstance(ranked, Failure): return ranked - news = None + news: str | None = None if args.changelog is not None: - news = with_bullet(changelog.read_text(encoding="utf-8") if changelog.exists() else "", args.changelog) - if isinstance(news, Failure): - return news + bulleted = with_bullet(changelog.read_text(encoding="utf-8") if changelog.exists() else "", args.changelog) + if isinstance(bulleted, Failure): + return bulleted + news = bulleted if unwritten := ranking.write(todo, ranked.text): return unwritten if news is not None and (unwritten := ranking.write(changelog, news)): diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index 7cafb0c3..05a49f2f 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -7,9 +7,9 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) -from release_plan import ranking from release_plan.test_ranking import DECISIONS, README, TODO from todo_item import main +from release_plan import ranking ADD = ["add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the `a | b` runs."] ROW = "| 6 | 0.1.0 | | | **Count the `a \\| b` runs.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 |" -- 2.52.0 From 520336646e01b2969cd387d4f68ee3715e534e7f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:39:25 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20the=20round?= =?UTF-8?q?=20saw=20no=20code,=20since=20.gitignore's=20allowlist=20left?= =?UTF-8?q?=20bin/todo=5Fitem=20untracked=20until=20the=20commit=20before?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From e90a7ba1ad3ae8dd86da522e8ee0d5ace5e5064f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:39:50 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Answer=20security=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From f6a8b2b6d9d751909b8acd68859fd7a633394ef5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:51:27 +0100 Subject: [PATCH 07/10] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=2013=20=F0=9F=9F=A1=20(1=20misread);=20end=20a=20?= =?UTF-8?q?detail=20only=20at=20a=20###=20.=20heading,=20print=20the?= =?UTF-8?q?=20whole=20help,=20refuse=20an=20empty=20bullet,=20an=20unreada?= =?UTF-8?q?ble=20changelog=20and=20###=20categories=20under=20Unreleased,?= =?UTF-8?q?=20take=20a=20heading=20saying=20unreleased=20as=20the=20sectio?= =?UTF-8?q?n,=20and=20test=20one=20behaviour=20each;=20the=20README=20modu?= =?UTF-8?q?le=20map=20is=20left=20as=20it=20is,=20as=20the=20PR=20says?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/todo_item/edits.py | 25 ++-- bin/todo_item/main.py | 59 +++++--- bin/todo_item/test_todo_item.py | 253 +++++++++++++++++++++++++------- 3 files changed, 259 insertions(+), 78 deletions(-) diff --git a/bin/todo_item/edits.py b/bin/todo_item/edits.py index 802bec79..696782c3 100644 --- a/bin/todo_item/edits.py +++ b/bin/todo_item/edits.py @@ -5,13 +5,15 @@ from release_plan.todo_table import cells, DETAILS, items_table, Table from failure import Failure from release_plan.ranking import stated -# A line that would end the item's detail, or open another one, inside ## Details. -HEADING = re.compile(r"^#{1,3} ", re.M) +# A line that would end ## Details (##) or could open another item's detail (###). +HEADING = re.compile(r"^#{2,3} ", re.M) UNRELEASED = "## Unreleased" +# The changelog's section for news not yet released: ## Unreleased, or a release heading such as `## 0.6.0 (unreleased)`. +UNRELEASED_SECTION = re.compile(r"^## .*unreleased.*\n+", re.M | re.I) def added(todo: str, named: dict[str, str], detail: str) -> tuple[int, str] | Failure: - """todo with an item filed under Next ID, and that ID; named holds its cells by column name, its Item cell a plain tagline.""" + """todo with an item filed under Next ID, and that ID; named holds its cells by column name, its Item cell the tagline, bold or not.""" next_id = stated(todo, "Next ID") if isinstance(next_id, Failure): return next_id @@ -21,7 +23,7 @@ def added(todo: str, named: dict[str, str], detail: str) -> tuple[int, str] | Fa if "\n" in tagline: return Failure("the tagline holds a line break; keep it on one line") if HEADING.search(detail): - return Failure("the detail holds a markdown heading, which would split ## Details; drop the #s") + return Failure("the detail holds a ## or ### heading, which would split ## Details; use #### or drop the #s") id_ = int(next_id) lines = re.sub(r"^`Next ID = [0-9]+`$", f"`Next ID = {id_ + 1}`", todo, count=1, flags=re.M).split("\n") table = held_table(lines) @@ -58,19 +60,24 @@ def finished(todo: str, id_: int) -> str | Failure: section = DETAILS.search(text) if section is None: return text - body = re.sub(rf"^### {id_}\. .*?(?=^### |\Z)", "", section.group(1), count=1, flags=re.M | re.S) + body = re.sub(rf"^### {id_}\. .*?(?=^### \d+\. |\Z)", "", section.group(1), count=1, flags=re.M | re.S) return text[:section.start(1)] + body + text[section.end(1):] def with_bullet(changelog: str, bullet: str) -> str | Failure: - """changelog with bullet first under ## Unreleased, which goes above the first release where missing; a new changelog where changelog is empty.""" - line = "- " + bullet.strip().removeprefix("- ") - if "\n" in line: + """changelog with bullet first under its UNRELEASED_SECTION, adding ## Unreleased above the first release heading where it has none; a new changelog where changelog is empty. Failure where that section holds ### subsections, since the bullet belongs under one of them.""" + text = bullet.strip().removeprefix("- ").strip() + if not text: + return Failure("the changelog bullet is empty") + if "\n" in text: return Failure("the changelog bullet holds a line break; keep it on one line") + line = f"- {text}" if not changelog.strip(): return f"# Changelog\n\n{UNRELEASED}\n\n{line}\n" - if section := re.search(rf"^{UNRELEASED}\n+", changelog, re.M): + if section := UNRELEASED_SECTION.search(changelog): rest = changelog[section.end():] + if re.search(r"^### ", re.split(r"^## ", rest, maxsplit=1, flags=re.M)[0], re.M): + return Failure(f"CHANGELOG.md's {section.group().strip()} holds ### subsections; add the bullet under the right one by hand, then finish with --no-changelog") return changelog[:section.end()] + line + "\n" + ("" if rest.startswith("- ") or not rest else "\n") + rest if release := re.search(r"^## ", changelog, re.M): return changelog[:release.start()] + f"{UNRELEASED}\n\n{line}\n\n" + changelog[release.start():] diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index 2d5527ea..aa899f67 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -4,19 +4,23 @@ usage: todo-item add --release --l --e --i --s [--move [--blocked-by ] [--exempt ] [<<'EOF' detail EOF] todo-item finish [--changelog | --no-changelog] -Works on the todo.md in the current folder, and the CHANGELOG.md and docs/decisions.md beside it. +Works on the todo.md in the current folder and the CHANGELOG.md beside it, and reads the README.md +and docs/decisions.md beside todo.md. The cells take the format rank_todo.py --help states; the letter flags take upper case too, as --L. add takes Next ID as the item's ID and raises Next ID by one. It writes the row, with the tagline in bold and each | in it escaped, and the detail it reads from stdin, if any, under ## Details. +The detail may hold no ## or ### heading. It prints `Filed item .` It writes nothing where ranking fails or scores the item under the bar. finish removes the item's row and its detail. With --changelog it adds the bullet first under -CHANGELOG.md's ## Unreleased, creating the section, or the file, where missing. Where CHANGELOG.md -exists, finish needs --changelog or --no-changelog, so no bullet is left out by mistake. It prints -`Finished item .` It writes nothing while docs/decisions.md cites the item. +CHANGELOG.md's ## Unreleased, or a ## heading that says unreleased, creating the section, or the +file, where missing. It refuses where that section holds ### subsections: add the bullet by hand. +Where CHANGELOG.md exists, finish needs --changelog or --no-changelog, so no bullet is left out by +mistake. It prints `Finished item .` It writes nothing while docs/decisions.md cites the item. -Exit 2 on bad arguments; exit 1, saying why, where it writes nothing. +Exit 2 on bad arguments, and 1, saying why, on any other failure. A message opening `not filed:` +or `not finished:` means it wrote nothing. """ import argparse import pathlib @@ -33,6 +37,9 @@ LETTERS = ("L", "E", "I", "S") def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.TextIO = sys.stdin) -> int: + if argv[:1] in (["-h"], ["--help"]): + print(__doc__.strip()) + return 0 args = parser().parse_args(argv) done = add(args, folder, stdin) if args.command == "add" else finish(args, folder) if isinstance(done, Failure): @@ -43,7 +50,7 @@ def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.T def parser() -> argparse.ArgumentParser: - parsed = argparse.ArgumentParser(prog="todo-item", description=__doc__.split("\n\n")[0]) + parsed = argparse.ArgumentParser(prog="todo-item") commands = parsed.add_subparsers(dest="command", required=True) adding = commands.add_parser("add") adding.add_argument("--release", required=True) @@ -67,6 +74,7 @@ def add(args: argparse.Namespace, folder: pathlib.Path, stdin: typing.TextIO) -> if isinstance(texts, Failure): return texts named = {"Release": args.release, BLOCKED_BY: args.blocked_by, "Exempt": args.exempt, "Item": args.tagline, MOVES: args.moves} + # Claude Code's Bash tool gives a command /dev/null as stdin (readlink /proc/self/fd/0 shows it), so without a heredoc read() returns "" at once. filed = added(texts[0], named | {letter: getattr(args, letter) for letter in LETTERS}, "" if stdin.isatty() else stdin.read()) if isinstance(filed, Failure): return Failure(f"not filed: {filed.reason}") @@ -84,8 +92,22 @@ def add(args: argparse.Namespace, folder: pathlib.Path, stdin: typing.TextIO) -> def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure: todo, changelog = folder / "todo.md", folder / "CHANGELOG.md" + texts = finish_texts(args, todo, changelog) + if isinstance(texts, Failure): + return Failure(f"not finished: {texts.reason}") + ranked, news = texts + if unwritten := ranking.write(todo, ranked.text): + return Failure(f"not finished: {unwritten.reason}") + if news is not None and (unwritten := ranking.write(changelog, news)): + return Failure(f"{unwritten.reason}; todo.md no longer holds item {args.id}, so add its bullet by hand") + report(todo, ranked) + return f"Finished item {args.id}." + + +def finish_texts(args: argparse.Namespace, todo: pathlib.Path, changelog: pathlib.Path) -> tuple[ranking.Ranked, str | None] | Failure: + """What finish writes: todo ranked without item args.id, and changelog's new text, None where finish leaves it as is.""" if changelog.exists() and args.changelog is None and not args.no_changelog: - return Failure("CHANGELOG.md exists beside todo.md; pass --changelog , or --no-changelog for an item consumers don't notice") + return Failure("CHANGELOG.md exists beside todo.md; pass --changelog , or --no-changelog where the repo publishes nothing") texts = ranking.read_all(todo) if isinstance(texts, Failure): return texts @@ -95,21 +117,18 @@ def finish(args: argparse.Namespace, folder: pathlib.Path) -> str | Failure: ranked = ranking.rank(text, *texts[1:]) if isinstance(ranked, Failure): return ranked - news: str | None = None - if args.changelog is not None: - bulleted = with_bullet(changelog.read_text(encoding="utf-8") if changelog.exists() else "", args.changelog) - if isinstance(bulleted, Failure): - return bulleted - news = bulleted - if unwritten := ranking.write(todo, ranked.text): - return unwritten - if news is not None and (unwritten := ranking.write(changelog, news)): - return Failure(f"{unwritten.reason}; todo.md no longer holds item {args.id}, so add its bullet by hand") - report(todo, ranked) - return f"Finished item {args.id}." + if args.changelog is None: + return ranked, None + try: + news = with_bullet(changelog.read_text(encoding="utf-8") if changelog.exists() else "", args.changelog) + except OSError as failure: + return Failure(f"{changelog}: {failure.strerror}") + except UnicodeDecodeError: + return Failure(f"{changelog}: not UTF-8") + return news if isinstance(news, Failure) else (ranked, news) def report(todo: pathlib.Path, ranked: ranking.Ranked) -> None: - """Print what ranking says beside the ranked file, as rank_todo.py does.""" + """Print ranking's notes and under-bar lines on stderr, each prefixed with todo.md's path, as rank_todo.py does.""" for line in ranked.notes + ranked.under_bar: print(f"{todo}: {line}", file=sys.stderr) diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index 05a49f2f..db7a4815 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -8,12 +8,21 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) from release_plan.test_ranking import DECISIONS, README, TODO -from todo_item import main +from todo_item import edits, main +from failure import Failure from release_plan import ranking ADD = ["add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the `a | b` runs."] -ROW = "| 6 | 0.1.0 | | | **Count the `a \\| b` runs.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 |" CHANGELOG = "# Changelog\n\n## Unreleased\n\n- Older news.\n\n## 0.1.0\n\n- First.\n" +# ## Details of the ranked fixture, without the trailing ## Notes. +DETAILS = "## Details\n\n### 3. Make it fast, `a | b`.\n\nFast detail.\n\n### 1. Ship the later thing.\n\nLater detail.\n\n" + + +class Terminal(io.StringIO): + """A stdin that reads as a terminal, so add must not read it.""" + + def isatty(self): + return True class TodoItem(unittest.TestCase): @@ -22,6 +31,7 @@ class TodoItem(unittest.TestCase): self.addCleanup(temp.cleanup) self.folder = pathlib.Path(temp.name) self.todo = self.folder / "todo.md" + self.changelog = self.folder / "CHANGELOG.md" (self.folder / "README.md").write_text(README) (self.folder / "docs").mkdir() (self.folder / "docs" / "decisions.md").write_text(DECISIONS) @@ -29,87 +39,232 @@ class TodoItem(unittest.TestCase): assert not isinstance(ranked, ranking.Failure) self.todo.write_text(ranked.text) - def run_main(self, *argv, stdin=""): + def run_main(self, *argv, stdin: str | io.StringIO = ""): with contextlib.redirect_stdout(io.StringIO()) as out, contextlib.redirect_stderr(io.StringIO()) as err: - code = main.main(list(argv), self.folder, io.StringIO(stdin)) + code = main.main(list(argv), self.folder, io.StringIO(stdin) if isinstance(stdin, str) else stdin) return code, out.getvalue(), err.getvalue() + def exit_code(self, *argv): + with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit) as raised: + main.main(list(argv), self.folder, io.StringIO()) + return raised.exception.code + def assert_ranked(self): self.assertEqual(ranking.check_failures(self.todo), []) + def details(self): + text = self.todo.read_text() + return text[text.index("## Details"):text.index("## Notes")] + + def lower_item_2_under_the_bar(self): + self.todo.write_text(self.todo.read_text().replace("**Tighten the tests.** | 1 | 2 | 1 | 2 | 4 |", "**Tighten the tests.** | 1 | 2 | 1 | 2 | 9 |")) + + +class Help(TodoItem): + def test_prints_the_whole_docstring_and_exits_0(self): + for flag in ("-h", "--help"): + with self.subTest(flag): + code, out, err = self.run_main(flag) + self.assertEqual((code, out, err), (0, main.__doc__.strip() + "\n", "")) + for fact in ("stdin", "--changelog", "--no-changelog", "Exit 2"): + self.assertIn(fact, out) + + +class BadArguments(TodoItem): + def test_exit_2(self): + for argv in ([], ADD[:1] + ADD[3:], ["finish"]): + with self.subTest(argv): + self.assertEqual(self.exit_code(*argv), 2) + class Add(TodoItem): - def test_takes_next_id_bumps_it_and_writes_the_row_and_detail_ranked(self): - self.assertEqual(self.run_main(*ADD, stdin="What the tagline leaves out.\n"), (0, "Filed item 6.\n", "")) - text = self.todo.read_text() - self.assertIn("`Next ID = 7`", text) - self.assertIn(ROW, text) - self.assertIn("### 6. Count the `a | b` runs.\n\nWhat the tagline leaves out.\n", text) + def test_takes_next_id_and_raises_it(self): + self.assertEqual(self.run_main(*ADD)[:2], (0, "Filed item 6.\n")) + self.assertIn("`Next ID = 7`", self.todo.read_text()) + + def test_writes_the_row_with_the_tagline_bold_and_its_pipes_escaped(self): + self.run_main(*ADD) + self.assertIn("| 6 | 0.1.0 | | | **Count the `a \\| b` runs.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 |", self.todo.read_text()) + + def test_takes_a_bold_tagline_upper_case_letters_blockers_and_exempt(self): + argv = ["add", "--release", "0.1.0", "--blocked-by", "2", "--exempt", "owner", "--L", "1", "--E", "1", "--I", "1", "--S", "1", "**Count the runs.**"] + self.assertEqual(self.run_main(*argv)[0], 0) + self.assertIn("| 6 | 0.1.0 | 2 | owner | **Count the runs.** | 1 | 1 | 1 | 1 | 1 | |", self.todo.read_text()) + + def test_writes_the_detail_from_stdin_into_the_one_details_section(self): + self.run_main(*ADD, stdin="What the tagline leaves out.\n") + self.assertEqual(self.details(), DETAILS.replace("### 3.", "### 6. Count the `a | b` runs.\n\nWhat the tagline leaves out.\n\n### 3.")) + + def test_leaves_the_file_ranked(self): + self.run_main(*ADD, stdin="Detail.") self.assert_ranked() - def test_files_no_detail_from_empty_stdin_and_takes_upper_case_letters_blockers_and_exempt(self): - argv = ["add", "--release", "0.1.0", "--blocked-by", "2", "--exempt", "owner", "--L", "1", "--E", "1", "--I", "1", "--S", "1", "**Count the runs.**"] - self.assertEqual(self.run_main(*argv)[:2], (0, "Filed item 6.\n")) - text = self.todo.read_text() - self.assertIn("| 6 | 0.1.0 | 2 | owner | **Count the runs.** | 1 | 1 | 1 | 1 | 1 | |", text) - self.assertNotIn("### 6.", text) - self.assert_ranked() + def test_files_no_detail_from_empty_stdin(self): + self.assertEqual(self.run_main(*ADD)[0], 0) + self.assertEqual(self.details(), DETAILS) + + def test_reads_no_detail_from_a_terminal(self): + self.assertEqual(self.run_main(*ADD, stdin=Terminal("Detail."))[0], 0) + self.assertEqual(self.details(), DETAILS) def test_creates_details_where_todo_has_none(self): self.todo.write_text(self.todo.read_text().split("## Details")[0].rstrip("\n") + "\n") self.assertEqual(self.run_main(*ADD, stdin="Detail.")[0], 0) - self.assertTrue(self.todo.read_text().endswith("## Details\n\n### 6. Count the `a | b` runs.\n\nDetail.\n")) + self.assertTrue(self.todo.read_text().endswith("| 1 by 9 | 228.4 |\n\n## Details\n\n### 6. Count the `a | b` runs.\n\nDetail.\n")) self.assert_ranked() - def test_writes_nothing_for_an_item_under_the_bar_or_one_ranking_rejects(self): - before = self.todo.read_text() - code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "Count the runs.") - self.assertEqual((code, err), (1, "not filed: item 6 scores 0.0, under the bar 2; delete it, or mark it with a reason the bar does not apply\n")) - code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "9", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count the runs.") - self.assertEqual((code, err), (1, "not filed: item 6's L '9' is not a whole number from 1 to 4\n")) - code, _, err = self.run_main("add", "--release", "0.1.0", "--l", "1", "--e", "1", "--i", "1", "--s", "1", "--moves", "1 by 9", "Count\nthe runs.") - self.assertEqual((code, err), (1, "not filed: the tagline holds a line break; keep it on one line\n")) - self.assertEqual(self.todo.read_text(), before) + def test_takes_a_detail_holding_a_one_or_four_hash_line(self): + self.assertEqual(self.run_main(*ADD, stdin="Run it so:\n\n# run as root\n\n#### Why\n\nBecause.")[0], 0) + self.assertIn("### 6. Count the `a | b` runs.\n\nRun it so:\n\n# run as root\n\n#### Why\n\nBecause.\n", self.todo.read_text()) + + def test_reports_ranking_lines_on_stderr_prefixed_with_todo_md(self): + self.lower_item_2_under_the_bar() + _, _, err = self.run_main(*ADD) + self.assertTrue(err.startswith(f"{self.todo}: item 2 "), err) + + def test_writes_nothing_where_it_refuses(self): + refused = { + "under the bar": ADD[:-3] + ["Count the runs."], + "a score ranking rejects": ADD[:4] + ["9"] + ADD[5:], + "a tagline with a line break": ADD[:-1] + ["Count\nthe runs."], + } + for case, argv in refused.items(): + with self.subTest(case): + before = self.todo.read_text() + code, out, err = self.run_main(*argv) + self.assertEqual((code, out), (1, "")) + self.assertTrue(err.startswith("not filed: "), err) + self.assertEqual(self.todo.read_text(), before) + self.assertIn("item 6", self.run_main(*refused["under the bar"])[2]) + + def test_writes_nothing_for_a_detail_holding_a_two_or_three_hash_line(self): + for detail in ("## Goals", "### Why", "### 2. Other"): + with self.subTest(detail): + before = self.todo.read_text() + code, _, err = self.run_main(*ADD, stdin=f"Detail.\n\n{detail}\n") + self.assertEqual(code, 1) + self.assertTrue(err.startswith("not filed: "), err) + self.assertEqual(self.todo.read_text(), before) class Finish(TodoItem): - def test_removes_the_row_and_detail_and_adds_the_bullet_first_under_unreleased(self): - (self.folder / "CHANGELOG.md").write_text(CHANGELOG) - self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, "Finished item 3.\n", "")) - text = self.todo.read_text() - self.assertNotRegex(text, r"(?m)^\| 3 \|") - self.assertNotIn("### 3.", text) - self.assertIn("### 1. Ship the later thing.\n\nLater detail.\n", text) - self.assert_ranked() - self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n- Older news.\n\n## 0.1.0\n\n- First.\n") + def test_removes_the_row(self): + self.assertEqual(self.run_main("finish", "3", "--no-changelog"), (0, "Finished item 3.\n", "")) + self.assertNotRegex(self.todo.read_text(), r"(?m)^\| 3 \|") - def test_creates_unreleased_or_the_changelog_where_missing(self): - (self.folder / "CHANGELOG.md").write_text("# Changelog\n\n## 0.1.0\n\n- First.\n") + def test_removes_the_detail_and_keeps_the_others(self): + self.run_main("finish", "3", "--no-changelog") + self.assertEqual(self.details(), "## Details\n\n### 1. Ship the later thing.\n\nLater detail.\n\n") + + def test_removes_a_detail_holding_a_sub_heading_whole(self): + self.todo.write_text(self.todo.read_text().replace("Fast detail.\n", "Fast detail.\n\n### Why\n\nFast tail.\n").replace("Later detail.\n", "Later detail.\n\n### Why\n\nLater tail.\n")) + self.assertEqual(self.run_main("finish", "3", "--no-changelog")[0], 0) + self.assertEqual(self.details(), "## Details\n\n### 1. Ship the later thing.\n\nLater detail.\n\n### Why\n\nLater tail.\n\n") + + def test_leaves_the_file_ranked(self): + self.run_main("finish", "3", "--no-changelog") + self.assert_ranked() + + def test_adds_the_bullet_first_under_unreleased(self): + self.changelog.write_text(CHANGELOG) + self.assertEqual(self.run_main("finish", "3", "--changelog", "Runs are fast."), (0, "Finished item 3.\n", "")) + self.assertEqual(self.changelog.read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n- Older news.\n\n## 0.1.0\n\n- First.\n") + + def test_creates_unreleased_above_the_first_release(self): + self.changelog.write_text("# Changelog\n\n## 0.1.0\n\n- First.\n") self.assertEqual(self.run_main("finish", "3", "--changelog", "- Runs are fast.")[0], 0) - self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n\n## 0.1.0\n\n- First.\n") - (self.folder / "CHANGELOG.md").unlink() + self.assertEqual(self.changelog.read_text(), "# Changelog\n\n## Unreleased\n\n- Runs are fast.\n\n## 0.1.0\n\n- First.\n") + + def test_creates_the_changelog_where_missing(self): self.assertEqual(self.run_main("finish", "2", "--changelog", "Tests are tight.")[0], 0) - self.assertEqual((self.folder / "CHANGELOG.md").read_text(), "# Changelog\n\n## Unreleased\n\n- Tests are tight.\n") + self.assertEqual(self.changelog.read_text(), "# Changelog\n\n## Unreleased\n\n- Tests are tight.\n") def test_needs_a_changelog_choice_where_a_changelog_exists(self): - (self.folder / "CHANGELOG.md").write_text(CHANGELOG) + self.changelog.write_text(CHANGELOG) before = self.todo.read_text() code, _, err = self.run_main("finish", "2") - self.assertEqual((code, err), (1, "CHANGELOG.md exists beside todo.md; pass --changelog , or --no-changelog for an item consumers don't notice\n")) + self.assertEqual(code, 1) + self.assertTrue(err.startswith("not finished: "), err) + for fact in ("CHANGELOG.md", "--changelog", "--no-changelog"): + self.assertIn(fact, err) self.assertEqual(self.todo.read_text(), before) - self.assertEqual(self.run_main("finish", "2", "--no-changelog"), (0, "Finished item 2.\n", "")) - self.assertEqual((self.folder / "CHANGELOG.md").read_text(), CHANGELOG) - self.assertNotRegex(self.todo.read_text(), r"(?m)^\| 2 \|") + + def test_leaves_the_changelog_as_is_with_no_changelog(self): + self.changelog.write_text(CHANGELOG) + self.assertEqual(self.run_main("finish", "2", "--no-changelog")[0], 0) + self.assertEqual(self.changelog.read_text(), CHANGELOG) + + def test_reports_ranking_lines_on_stderr_prefixed_with_todo_md(self): + self.lower_item_2_under_the_bar() + _, _, err = self.run_main("finish", "3", "--no-changelog") + self.assertTrue(err.startswith(f"{self.todo}: item 2 "), err) def test_writes_nothing_for_an_item_a_decision_cites(self): before = self.todo.read_text() code, _, err = self.run_main("finish", "5", "--changelog", "Writes moved out.") - self.assertEqual((code, err), (1, 'docs/decisions.md cites "`todo.md` item 5", which todo.md no longer holds; revise that decision to say what holds now\n')) + self.assertEqual(code, 1) + self.assertTrue(err.startswith("not finished: "), err) + self.assertIn("item 5", err) self.assertEqual(self.todo.read_text(), before) - self.assertFalse((self.folder / "CHANGELOG.md").exists()) + self.assertFalse(self.changelog.exists()) def test_fails_on_an_item_the_table_does_not_hold(self): - self.assertEqual(self.run_main("finish", "9", "--no-changelog"), (1, "", "todo.md holds no item 9\n")) + code, out, err = self.run_main("finish", "9", "--no-changelog") + self.assertEqual((code, out), (1, "")) + self.assertTrue(err.startswith("not finished: "), err) + self.assertIn("9", err) + + def test_fails_on_a_todo_md_without_an_items_table(self): + self.todo.write_text("# todo\n") + code, _, err = self.run_main("finish", "3", "--no-changelog") + self.assertEqual(code, 1) + self.assertIn("no items table", err) + self.assertEqual(self.todo.read_text(), "# todo\n") + + def test_writes_neither_file_for_a_bullet_it_refuses(self): + changelogs = { + "an empty bullet": (CHANGELOG, ""), + "a whitespace bullet": (CHANGELOG, " \t "), + "a bullet with a line break": (CHANGELOG, "Runs\nare fast."), + "an Unreleased section with ### subsections": ("# Changelog\n\n## Unreleased\n\n### Security\n\n- Older news.\n", "Runs are fast."), + } + for case, (changelog, bullet) in changelogs.items(): + with self.subTest(case): + self.changelog.write_text(changelog) + before = self.todo.read_text() + code, _, err = self.run_main("finish", "3", "--changelog", bullet) + self.assertEqual(code, 1) + self.assertTrue(err.startswith("not finished: "), err) + self.assertEqual((self.todo.read_text(), self.changelog.read_text()), (before, changelog)) + + def test_fails_on_a_changelog_that_is_not_utf_8(self): + self.changelog.write_bytes(b"# Changelog\n\n\xff\n") + before = self.todo.read_text() + code, _, err = self.run_main("finish", "3", "--changelog", "Runs are fast.") + self.assertEqual(code, 1) + self.assertTrue(err.startswith("not finished: "), err) + self.assertIn(str(self.changelog), err) + self.assertEqual(self.todo.read_text(), before) + + +class WithBullet(unittest.TestCase): + def test_keeps_a_blank_line_before_prose_under_unreleased(self): + self.assertEqual(edits.with_bullet("# Changelog\n\n## Unreleased\n\nSome note.\n", "New."), "# Changelog\n\n## Unreleased\n\n- New.\n\nSome note.\n") + + def test_appends_unreleased_to_a_changelog_without_a_release(self): + self.assertEqual(edits.with_bullet("# Changelog\n", "New."), "# Changelog\n\n## Unreleased\n\n- New.\n") + + def test_takes_a_release_heading_marked_unreleased_as_the_section(self): + self.assertEqual(edits.with_bullet("# Changelog\n\n## 0.6.0 (Unreleased)\n\n- Old.\n\n## 0.5.0\n", "New."), "# Changelog\n\n## 0.6.0 (Unreleased)\n\n- New.\n- Old.\n\n## 0.5.0\n") + + def test_refuses_an_unreleased_section_with_subsections_and_says_to_add_by_hand(self): + refused = edits.with_bullet("# Changelog\n\n## Unreleased\n\n### Security\n\n- Old.\n\n## 0.5.0\n", "New.") + self.assertIsInstance(refused, Failure) + assert isinstance(refused, Failure) + self.assertIn("by hand", refused.reason) + + def test_takes_subsections_of_a_release_below_unreleased(self): + self.assertEqual(edits.with_bullet("## Unreleased\n\n- Old.\n\n## 0.5.0\n\n### Security\n", "New."), "## Unreleased\n\n- New.\n- Old.\n\n## 0.5.0\n\n### Security\n") if __name__ == "__main__": -- 2.52.0 From 4ec3aea9182fb2ddb995333c90d7401cafe0dd31 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:51:27 +0100 Subject: [PATCH 08/10] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20the=20fi?= =?UTF-8?q?xes=20went=20in=20the=20stability=20commit:=20the=20whole=20hel?= =?UTF-8?q?p,=20###=20categories=20refused,=20and=20not=20finished:=20on?= =?UTF-8?q?=20every=20refusal=20that=20writes=20nothing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From f24a653a02d54d4a7ee2693c64c00409284f3b96 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:51:27 +0100 Subject: [PATCH 09/10] =?UTF-8?q?Answer=20prose=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20the=20help?= =?UTF-8?q?=20fix=20went=20in=20the=20stability=20commit;=20say=20what=20f?= =?UTF-8?q?inish=20does=20in=20CLAUDE.md,=20reword=20the=20changelog,=20RE?= =?UTF-8?q?ADME=20and=20rules=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++-- CLAUDE.md | 2 +- README.md | 4 ++-- rules/todo-items.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d614cca..466813f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ## Unreleased -- `todo-item add` now files an item in `todo.md` with one command. It gives the item `Next ID`, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file. -- `todo-item finish ` now removes a finished item from `todo.md`, its row and its detail, and adds its bullet first under `CHANGELOG.md` → `## Unreleased`. Where a `CHANGELOG.md` exists, it asks for `--changelog ` or `--no-changelog`, so no bullet is left out by mistake. +- `todo-item add` now files an item in `todo.md` with one command. It takes `Next ID` as the item's ID, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file. +- `todo-item finish ` now removes a finished item's row and detail from `todo.md`. With `--changelog `, it also adds that bullet first under `CHANGELOG.md` → `## Unreleased`. Where a `CHANGELOG.md` exists, it refuses to run without `--changelog ` or `--no-changelog`, so no bullet is left out by mistake. - A worker whose review rules its work below standard now fixes it on its own rung where the fix changes only prose, a comment or docstring included. It hands the fix to a higher rung only where code, config or tests change. - `loop-claude`'s judge now sends a question you answered earlier in the chunk back to the worker, quoting your answer, unless the question ends with the words of your answer that leave it open. You are asked only about what your answer left open. - `score-outcomes` now shows, beside what each finished item's chunk measured, the size of the files and folders its tagline or detail names in backticks: how many files, and how many lines, as they stood before its chunk. diff --git a/CLAUDE.md b/CLAUDE.md index 66461aa3..90db7dbd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,7 +15,7 @@ How work proceeds in any repo, unless the repo's `AGENTS.md` says otherwise. The - **Ask, don't guess.** Three choices are always the human's: a goal; a release, meaning the items planned into it and when it is cut; and a change to loop-claude's routing ladder, its rungs included. Any other rule that asks the human's approval reserves that choice too. Ask about a reserved choice. For any other choice, first check whether the goals already answer it. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Otherwise take the option you would recommend, and record it with its reason: in the item's detail, or, where it governs later work, as the next sentence says. A recommendation you can give a reason for is not a guess. Ask only where you have no recommendation. Write every answer once, where it belongs, never only in chat: a goal in `README.md`, a working rule in `AGENTS.md`, a standing choice in a comment at the one place it governs, or in `docs/decisions.md` once made in more than one place. When an answer holds a goal and a choice, write the goal in the README, and record as a choice only what the goal leaves open. - **Bench a syntax with the people who write it.** Before a new or changed spelling of something users read or write ships — markdown, HTML, a config key, a CLI flag — a panel of fresh-context readers, seated as those users from the README's `## Audience`, picks it. - **Implement the simplest change that solves the item, and ship it with `/larv-review`.** Whenever a test can check the change, write that test first and see it fail. Take its expected values from the item, never from the code. larv-review's reviewers hold the change to the technical principles, and a finding against one names it. Read a file under `~/.claude/principles/` only when the item changes it, a finding or a record you write names it, or you decline a finding. -- **Remove a finished item's row and detail from `todo.md`, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish `, with `--changelog ` or `--no-changelog`, does both. +- **Remove a finished item's row and detail from `todo.md`, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish ` removes the row and detail, and adds the bullet you pass with `--changelog `; it refuses while a decision cites the item. - **Releases are the human's.** The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision. - **Open each `todo.md` item or ticket with a bold one-sentence tagline**, so the taglines alone say what a release holds. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and says nothing about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: `**Accept undefined in MetadataValue and drop such keys on output.**` BANNED: `MetadataValue accepts undefined; such keys are dropped on output`. - **File a security finding the moment it is found.** A security finding — a leaked credential, secret or PII, an auth bypass, an injection — goes under the next release, marked `security`, naming the exposure and the path it reaches. `~/.claude/bin/rank_todo.py` ranks it first in its release, after only the open questions, which wait for me. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will unmark it if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius. diff --git a/README.md b/README.md index 7fb3e75a..7a7e11b2 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it. - `subagent-rung [--plan] ` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule. -- `todo-item add …` files an item in a project's `todo.md` under its `Next ID`, and `todo-item finish ` removes a finished one and adds its bullet to `CHANGELOG.md`; both rank the file, and `todo-item --help` states the flags. +- `todo-item add …` files an item in a project's `todo.md`, taking `Next ID` as the item's ID, and `todo-item finish ` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`; both rank the file, and `todo-item --help` states the flags. Test on the host with `uvx --python "$(command -v python3)" --with pytest-xdist==3.8.0 pytest==9.2.0 -n 4 bin`. It needs `uv` on `PATH`, which fetches pytest, pytest-xdist and mypy. pytest-xdist runs the tests in four workers, one heavy slot's CPUs (`docs/decisions.md` → `bin/: the tools support only the latest stable Python, …`). `python3 -m unittest discover -s bin -p 'test_*.py'` runs the same tests one at a time. Test the bench's scripts with `python3 -m unittest discover -s workflow-bench -p 'test_*.py'`. @@ -139,7 +139,7 @@ Then, in the copy: `uvx --with pytest==9.2.0 'mutmut>=3,<4' run && uvx --with py - `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read. - `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them. - `records/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, stamps times in UTC, and replaces a file in one step, private where it is new. -- `release_plan/` reads `todo.md`'s items table and release versions, says which release is next and whether it is ready to cut (`release_standing.py`), and ranks the plan (`ranking.py`, which `rank_todo.py`, `todo_item`, `larv_review` and `rule_hook` import). +- `release_plan/` reads `todo.md`'s items table and release versions, says which release is next and whether it is ready to cut (`release_standing.py`), and ranks the plan (`ranking.py`, which `larv_review`, `rank_todo.py`, `rule_hook` and `todo_item` import). - `repo_checks/` tests the repo itself. - `review_rules/` holds the larv-review rules that several tools apply: its passes, its review folder, its round commit titles and the comprehension history's format. - `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls. diff --git a/rules/todo-items.md b/rules/todo-items.md index 7a2cdce8..4d2fdf4e 100644 --- a/rules/todo-items.md +++ b/rules/todo-items.md @@ -6,7 +6,7 @@ paths: # Todo items (`todo.md`) - **`todo.md` is mandatory in every project, in the shape `rank_todo.py --help` shows**, which `~/.claude/bin/rank_todo.py` checks and ranks; its `--help` shows a valid file. `## Scoring` holds the formula and the bar; `## Items` is one table of every item; `## Details` holds each item's detail under its ID. `## Renamed` marks each renamed release with a line such as `- 0.2.1 renamed to 0.3.0`; `rank_todo.py --help` says what a mark does. Cite an item by its ID. The formula and bar are the project's own to tune. -- **File an item with `~/.claude/bin/todo-item add`.** It gives the item `Next ID`, raises `Next ID`, writes the row and the detail it reads from stdin, and ranks the file; `todo-item --help` shows the flags. +- **File an item with `~/.claude/bin/todo-item add`.** It reads the item's detail from stdin and ranks the file; `todo-item --help` shows the flags. - **Order items only by score and the Blocked by column.** An item's Blocked by cell lists the IDs of the items that must be done before it starts, such as `12, 14`; `rank_todo.py --help` says how it ranks them. No text in `todo.md` outside the table orders items: where an item must go first, score it so, and say why in its detail. - **Plan only on the project's rung or above.** loop-claude's prompt tells you when you run below it. Below it, never score or re-score an item, move it between releases, split a milestone into items, delete an item under the bar, rewrite a filed item's tagline or detail, or choose or replace an item in `docs/score-anchors.md`. Draft each new item, each change to a filed item, and each change to the anchors, instead. Before your next commit, launch one subagent to apply the drafts, score them and set their release. Launch it on the rung `CLAUDE.md`'s delegation rule gives a subagent that files or scores items. Keep the scores and releases it writes. For a security finding, launch it at once. Any rung may remove a finished item's row and detail, and score a delegated task's L. A subagent launched for another task leaves `todo.md` alone. - **An item's release allows the bump that semver read strictly asks for.** An item that changes what exists needs a major, or before 1.0.0 a minor. One that only adds needs a minor, and a fix a patch. -- 2.52.0 From e97d30f809656db0c123f2a5bf5a6d4645a26975 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 01:52:22 +0100 Subject: [PATCH 10/10] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0