Read the prose language and the title and branch templates from the project's config

This commit is contained in:
2026-11-14 01:14:08 +01:00
parent 82f4bbd91b
commit ce87a519f0
22 changed files with 134 additions and 29 deletions
+1 -1
View File
@@ -2,11 +2,11 @@ import dataclasses
import re
import typing
from project_config import templates
from failure import Failure
from review_rules.comprehension_history import HISTORY
from release_plan.todo_table import Item, items
from reading_cost.figures import RECORD
from project_config import templates
from text_files.utc_stamp import utc
# The plan, and the records tools append to: none of their lines are the chunk's work.
+1 -1
View File
@@ -6,8 +6,8 @@ from failure import Failure
from git_cli.git_repo import git, Git, text_at
from project_config.main import located
from project_config.settings import ProjectConfig
from project_config import templates
from record_store.stores import store
from project_config import templates
# Where branch_chunks reads the plan and the records, by the setting that names each in a project's config.
+2 -2
View File
@@ -82,10 +82,10 @@ class CutBranch(unittest.TestCase):
self.assertEqual([found.titles for found in found.chunks], [("Take \x1e and \x1f",)])
def test_reads_each_title_as_its_summary_in_the_projects_commit_title_template(self):
log = f"\x00{'a' * 40} 100 100 \x1faaaaaaa\x1fPAY-7 - Drop item 6: moot\n\nb.py\n\x00{'b' * 40} 90 90 \x1fbbbbbbb\x1fFrom before the template\n\nb.py\n"
log = f"\x00{'a' * 40} 100 100 {'b' * 40}\x1faaaaaaa\x1fPAY-7 - Drop item 6: moot\n\nb.py\n\x00{'b' * 40} 90 90 \x1fbbbbbbb\x1fFrom before the template\n\nb.py\n"
found = cut_branch(log, "PAY-{id} - {summary}")
self.assertNotIsInstance(found, Failure)
self.assertEqual([title for chunk in found.chunks for title in chunk.titles], ["Drop item 6: moot", "From before the template"])
self.assertEqual(sorted(title for chunk in found.chunks for title in chunk.titles), ["Drop item 6: moot", "From before the template"])
def test_fails_on_a_commit_it_cannot_read(self):
self.assertIsInstance(cut_branch(f"\x00{'a' * 40} 100\x1faaaaaaa\n"), Failure)
+17 -3
View File
@@ -11,7 +11,9 @@ pull request only while its head is the commit checked out, so push before you r
open pushes the branch, setting its upstream, and opens a draft pull request into origin's
default branch. <title> is one line, as ~/.claude/CLAUDE.md → "Git, commits, and PRs"
says, and <body> is the pull request's summary. Where the branch's pull request is open
says, and <body> is the pull request's summary. It refuses a <title> that doesn't fit the
`pull-request-title` template the project's config names (`project-config --help`), as
ready does, and fails where no config names the checkout. Where the branch's pull request is open
already, it opens no second one. On origin's default branch it refuses without pushing anything.
sync fetches origin and merges its default branch into the branch checked out, where the
branch does not hold it already, and prints which it did. Then, where the project's config
@@ -60,6 +62,7 @@ from deploy_release.forge import checks_passed, gitea, merged_pull, open_pull, r
from failure import Failure
from chunk_preflight.gathered import Forge
from chunk_preflight.choices import forge_of
from project_config import templates
BIN = pathlib.Path(__file__).resolve().parents[1]
# How long merge waits for a check to report before it takes a pull request without any as passed: CI queues its checks within seconds of a push, and merge may run right after one.
@@ -89,11 +92,11 @@ def step(argv: list[str], run: Run) -> str | Failure:
"""Run the step argv names: the line to print, or a Failure. A malformed argv doesn't run anything."""
match argv:
case ["open", title, *body] if len(body) <= 1 and not title.startswith("-"):
return Failure("give a title of one line") if not one_line(title) else opened(title, body[0] if body else "", run)
return Failure("give a title of one line") if not one_line(title) else misfit(title, run) or opened(title, body[0] if body else "", run)
case ["sync"]:
return synced(run)
case ["ready", *title] if len(title) <= 1 and not any(given.startswith("-") for given in title):
return Failure("give a title of one line") if title and not one_line(title[0]) else marked_ready(run, title[0] if title else None)
return Failure("give a title of one line") if title and not one_line(title[0]) else (misfit(title[0], run) if title else None) or marked_ready(run, title[0] if title else None)
case ["merge"]:
return merged(run)
case ["clean"]:
@@ -101,6 +104,17 @@ def step(argv: list[str], run: Run) -> str | Failure:
return Failure(USAGE)
def misfit(title: str, run: Run) -> Failure | None:
"""Why title doesn't fit the `pull-request-title` template the project's config names; None where it fits. A config that cannot be read fails, so that no pull request reaches the project's owners under a title they don't use."""
template = run([str(BIN / "project-config"), "pull-request-title"])
if isinstance(template, Failure):
return template
template = template.rstrip("\n")
if templates.fits(template, title.strip()):
return None
return Failure(f"title the pull request as the project's config asks, `{template}`, where {{id}} is the ID of the chunk's first item; {title.strip()!r} doesn't fit")
def one_line(title: str) -> bool:
return bool(title.strip()) and "\n" not in title
+18
View File
@@ -25,6 +25,7 @@ GH_CHECKS = ["gh", "pr", "checks", "12", "--watch", "--fail-fast"]
TEA_BRANCH = ["tea", "api", "repos/{owner}/{repo}/branches/main"]
TEA_STATUS = ["tea", "api", f"repos/{{owner}}/{{repo}}/commits/{HEAD}/status"]
OWED = [str(pathlib.Path(__file__).resolve().parents[1] / "larv-review"), "scoring-run-owed"]
TITLE = [str(pathlib.Path(__file__).resolve().parents[1] / "project-config"), "pull-request-title"]
WAITS = [str(pathlib.Path(__file__).resolve().parents[1] / "project-config"), "wait-for-approval"]
GH_DECISION = ["gh", "pr", "view", "12", "--json", "reviewDecision"]
@@ -50,6 +51,7 @@ class Checkout:
("git", "rev-parse", "HEAD"): f"{HEAD}\n",
("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD"): "origin/main\n",
tuple(WAITS): "false\n",
tuple(TITLE): "{summary}\n",
}
def __call__(self, command: list[str]) -> str | Failure:
@@ -105,6 +107,22 @@ class Open(unittest.TestCase):
self.assertIsInstance(step(["open", "Do it"], checkout), Failure)
self.assertEqual(checkout.acted(), [])
def test_a_title_that_does_not_fit_the_configs_template_is_refused_before_anything_runs(self):
for argv in (["open", "Do it"], ["ready", "Do it"]):
with self.subTest(argv=argv):
checkout = Checkout(GITHUB, open=argv[0] == "ready")
checkout.answers[tuple(TITLE)] = "PAY-{id} - {summary}\n"
refused = step(argv, checkout)
assert isinstance(refused, Failure), refused
self.assertIn("`PAY-{id} - {summary}`", refused.reason)
self.assertEqual(checkout.acted(), [])
self.assertNotIsInstance(step([argv[0], "PAY-7 - Do it"], checkout), Failure)
checkout.answers[tuple(TITLE)] = Failure("no config names the checkout")
self.assertEqual(step(argv, checkout), Failure("no config names the checkout"))
untitled = Checkout(GITHUB, open=True)
untitled.answers[tuple(TITLE)] = Failure("no config names the checkout")
self.assertNotIsInstance(step(["ready"], untitled), Failure)
def test_a_title_of_more_than_one_line_or_a_second_body_is_refused_before_anything_runs(self):
for argv, refusal in ((["open", "Do it\nand more"], "give a title of one line"), (["open", " "], "give a title of one line"), (["open", "Do it", "Body", "More"], USAGE)):
with self.subTest(argv):
+1 -1
View File
@@ -129,7 +129,7 @@ def preflight(root: pathlib.Path, timeout: float, make: bool) -> list[str] | Fai
if isinstance(config, Failure):
return config
outside = None if config.tracked("plan") else config.paths["plan"]
held = default_plan(str(root), ref, config.place("plan"), store(config, "changelog"))
held = default_plan(str(root), ref, config.place("plan"), store(config, "changelog"), title=config.commit_title)
plan = planned(held.todo, held.cut, ref, outside, config.branch)
item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout, make)
# A `checkout:` path lands in the worktree the chunk works in.
+4 -1
View File
@@ -161,6 +161,7 @@ import typing
from git_cli.git_repo import branch_titles, default_branch, git, top
from review_rules.round_titles import cap, CAP, RELEASE_REVIEW_CAP, round_counts
from project_config.main import commit_title
from failure import Failure
from review_rules.comprehension_history import FLOOR
from larv_review.history_changes import history_changes
@@ -174,6 +175,7 @@ from larv_review.plan import plan_reasons
from larv_review.scoring_setup import prepare_scoring
from larv_review.history_commands import read_agreement, read_places, record_ruling, record_scoring
from larv_review.reviewer_header import reviewer_header
from project_config import templates
class Command(typing.NamedTuple):
@@ -313,7 +315,8 @@ def round_count(default: str) -> Failure | None:
titles = branch_titles(default)
if isinstance(titles, Failure):
return titles
for name, count in round_counts(titles).items():
template = commit_title(None, pathlib.Path.home())
for name, count in round_counts([templates.summary_of(template, title) for title in titles]).items():
print(f"{name}: {count}{cap_note(count, cap(name)) if name in PASSES else ', not a pass: check the commit title'}")
return None
+1 -1
View File
@@ -75,7 +75,7 @@ def plan_reasons(ref: str, ids: list[int] | None, home: pathlib.Path) -> list[st
return decisions
if OPTED_OUT.search(decisions):
return []
held = default_plan(checkout, ref, config.place("plan"), stores.store(config, "changelog"))
held = default_plan(checkout, ref, config.place("plan"), stores.store(config, "changelog"), title=config.commit_title)
before = held.todo
if isinstance(before, Failure):
return before
+8 -3
View File
@@ -4,15 +4,16 @@ import pathlib
from git_cli.git_repo import branch_titles, git, top
from review_rules.round_titles import cap, round_counts
from project_config.main import commit_title, located
from failure import Failure
from chunk_preflight.choices import forge_of
from larv_review.history_commands import history_file, places_report
from record_store.stores import local_file, store
from project_config.main import located
from review_rules.review_folder import made_review_folder
from deploy_release.forge import open_pull, runner
from review_rules.reviewer_context import principles_line, starts_bare
from review_rules.review_passes import REVIEWERS
from project_config import templates
# The passes whose reviewer is given the places: skills/larv-review/SKILL.md → "Comprehension check" → "Places".
TAKE_PLACES = ("architecture", "stability")
@@ -37,6 +38,8 @@ class Launch:
# The project's `AGENTS.md`, where its config puts it, and a local file of its decision log.
rules: pathlib.Path
decisions: pathlib.Path
# The language the project's config names for its prose.
language: str
def asked(self) -> pathlib.Path:
"""The round's report, which asks for the rerun where there is one."""
@@ -54,6 +57,7 @@ class Launch:
f"Diff: {self.diff}",
f"Technical principles: {self.principles}",
f"Goals and audience: {self.goals}",
f"Prose language: {self.language}.",
*([f"Places: {self.folder / 'places.md'}"] if self.pass_ in TAKE_PLACES else []),
*([principles] if self.bare and (principles := principles_line(self.rules, self.decisions)) else []),
])
@@ -72,7 +76,8 @@ def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path) -
titles = branch_titles(default)
if isinstance(titles, Failure):
return titles
round_ = unanswered_round(titles, pass_)
template = commit_title(None, home)
round_ = unanswered_round([templates.summary_of(template, title) for title in titles], pass_)
if isinstance(round_, Failure):
return round_
found = [top(), *(git(*args) for args in (["symbolic-ref", "--short", "HEAD"], ["rev-parse", "--short", "HEAD"], ["merge-base", "HEAD", default]))]
@@ -93,7 +98,7 @@ def reviewer_header(default: str, pass_: str, rerun: bool, home: pathlib.Path) -
decisions = local_file(store(config, "decisions"), folder / "decisions.md")
if isinstance(decisions, Failure):
return decisions
launch = Launch(pass_, round_, rerun, pull_named(worktree, branch), worktree, branch, base, default, folder, folder / f"branch-{head}.diff", principles, config.paths["goals-and-audience"], starts_bare(next((agent for name, agent in REVIEWERS.items() if name == pass_), ""), home), config.paths["working-rules"], decisions)
launch = Launch(pass_, round_, rerun, pull_named(worktree, branch), worktree, branch, base, default, folder, folder / f"branch-{head}.diff", principles, config.paths["goals-and-audience"], starts_bare(next((agent for name, agent in REVIEWERS.items() if name == pass_), ""), home), config.paths["working-rules"], decisions, config.language)
if rerun and not launch.asked().exists():
return Failure(f"no report asked for a rerun of {pass_}'s round {round_}: {launch.asked()} is missing; relaunch before you commit the round's answers")
written = write_inputs(launch, base, home)
+8
View File
@@ -1080,6 +1080,7 @@ class LarvReviewTool(unittest.TestCase):
f"Diff: {folder}/branch-{short}.diff\n"
f"Technical principles: {self.checkout.parent}/principles\n"
f"Goals and audience: {self.checkout}/README.md\n"
"Prose language: English.\n"
f"Places: {folder}/places.md\n"
)), ran.stderr)
self.assertEqual((folder / f"branch-{short}.diff").read_text(), self.git("diff", base, "HEAD"))
@@ -1163,6 +1164,13 @@ class LarvReviewTool(unittest.TestCase):
def test_reviewer_header_names_the_principles_folder_the_projects_config_sets(self):
self.assertEqual(self.header_line("Technical principles:", "prose"), f"Technical principles: {self.checkout.parent}/principles")
def test_reviewer_header_names_the_language_and_counts_rounds_through_the_commit_title_the_projects_config_sets(self):
self.config.write_text(PROJECT_CONFIG + 'language = "Swedish"\ncommit-title = "PAY-{id} - {summary}"\n')
self.commit("PAY-7 - Answer prose round 1: 0 🔴, 1 🟡 (0 misread); a")
self.assertEqual(self.header_line("Prose language:", "prose"), "Prose language: Swedish.")
self.assertEqual(self.header_line("Pass:", "prose"), "Pass: prose, round 2.")
self.assertIn("prose: 1\n", self.run_tool("round-count").stdout)
def test_reviewer_header_names_the_goals_file_the_projects_config_sets(self):
self.config.write_text(PROJECT_CONFIG.replace('"checkout:README.md"', '"folder:goals.md"'))
self.assertEqual(self.header_line("Goals and audience:", "principles"), f"Goals and audience: {self.config.parent}/goals.md")
+1 -1
View File
@@ -80,7 +80,7 @@ def fetched_plan(loop: Loop) -> DefaultPlan | Failure:
if config.tracked("plan") is None:
say(UNSEEN_RELEASES, loop.effects)
ref = default_ref(loop.root, ORIGIN_TIMEOUT, run=loop.effects.git)
return ref if isinstance(ref, Failure) else default_plan(loop.root, ref, config.place("plan"), store(config, "changelog"), loop.effects.git)
return ref if isinstance(ref, Failure) else default_plan(loop.root, ref, config.place("plan"), store(config, "changelog"), loop.effects.git, title=config.commit_title)
def plan_item(plan: DefaultPlan | Failure, effects: Effects) -> Item | None:
+20 -4
View File
@@ -6,7 +6,7 @@ Run inside a checkout, or a worktree of one. It finds the config that names the
~/.claude-projects/<key>/config.toml, and prints each setting and its absolute path, as in
`plan: /home/me/code/acme/todo.md`. Given a setting, it prints only that setting's path.
The config is TOML. `checkout` names the project's main checkout, and every other setting but `wait-for-approval` is a path:
The config is TOML. `checkout` names the project's main checkout, and every setting in the example below is a path:
"checkout:<path>" inside the checkout, "folder:<path>" inside the config's own folder, or one that
starts with / or ~/. In a worktree, a "checkout:" path is the worktree's own file.
@@ -26,13 +26,29 @@ a path that starts with / or ~/ and lies outside the checkout and the config's f
"~/.claude-projects/acme-billing.env". Where it is left out, the project has no credentials file, and
a tool that needs one fails naming the setting. It is printed with the others only where it is set.
`wait-for-approval` is the other optional setting, true or false: whether `chunk-pr merge` waits for a human's
`wait-for-approval` is an optional setting, true or false: whether `chunk-pr merge` waits for a human's
approval of the pull request, as its branch protection requires on GitHub, before it merges. Left out, it is
false. `project-config wait-for-approval` prints true or false; the full listing shows the setting only where
it is true.
Four optional settings say how the project writes, for a project whose owners don't write as
~/.claude/CLAUDE.md does:
language = "Swedish"
commit-title = "PAY-{id} - {summary}"
pull-request-title = "PAY-{id} - {summary}"
branch = "feature/PAY-{id}"
`language` names the language of the project's prose by its English name; left out, it is English.
The others are templates. {summary} is the one line that says what a commit or pull request does,
and {id} is the ID of the chunk's first plan item. A title template holds {summary} once and {id}
at most once; left out, it is "{summary}". `branch` holds {id} once, among letters, digits and
. _ / -; left out, it is "item-{id}". A template has no way to write a literal { or }.
`project-config <setting>` prints each one's value, and the full listing shows it only where the
config sets it to something else than it is when left out.
Exit 1, naming each fault on stderr, where no config names the checkout, or its config leaves out a
setting, names an unknown one, misspells a path or sets `wait-for-approval` to anything but true or
setting, names an unknown one, misspells a path, a language or a template, or sets `wait-for-approval` to anything but true or
false, and where `env-file` is asked for and not set. No path setting has a default.
"""
import pathlib
@@ -40,8 +56,8 @@ import sys
from project_config.settings import CONFIG, ENV_FILE, load, OPTIONAL, ProjectConfig, SETTINGS, WAIT_FOR_APPROVAL
from failure import Failure
from project_config import templates
from git_cli.git_repo import git, Git
from project_config import templates
def main(argv: list[str]) -> int:
+8 -6
View File
@@ -9,6 +9,7 @@ from release_plan.todo_table import Item, items, next_item, renames
from project_config.settings import Place
from text_files.markdown_text import sections
from record_store import stores
from project_config import templates
# The version a branch with no v* tag and no dated CHANGELOG.md heading counts as cut: below every release, 0.0.0 included, so that every release todo.md names comes after it.
BEFORE_FIRST_RELEASE = (-1, 0, 0)
@@ -95,14 +96,14 @@ class DefaultPlan:
cut: LastCut
def default_plan(root: str, ref: str, plan: Place, changelog: stores.RecordStore, run: Git = git) -> DefaultPlan:
"""What ref, the default branch as last fetched, holds for the pick, read in the checkout at root through run. plan is where the project's config puts todo.md, and changelog the store it names for the changelog."""
def default_plan(root: str, ref: str, plan: Place, changelog: stores.RecordStore, run: Git = git, *, title: str = templates.TITLE) -> DefaultPlan:
"""What ref, the default branch as last fetched, holds for the pick, read in the checkout at root through run. plan is where the project's config puts todo.md, changelog the store it names for the changelog, and title its `commit-title` template."""
tag = newest_tag(root, merged_into=ref, run=run)
changes = stores.held_at(ref, changelog, root, run)
after = dated_cut(tag, changes)
since = tag if after is None else heading_commit(after, ref, changelog, root, run)
commits = since if isinstance(since, Failure) else commits_since(since, ref, root, run)
reviewed = tag if isinstance(tag, Failure) else release_reviewed(tag, ref, root, after, run)
reviewed = tag if isinstance(tag, Failure) else release_reviewed(tag, ref, root, after, run, title)
return DefaultPlan(held_at(ref, plan, root, run), LastCut(tag, changes, commits, todos_since(tag, ref, plan, root, run), reviewed))
@@ -127,15 +128,16 @@ def heading_commit(release: Release, ref: str, changelog: stores.RecordStore, cw
return added if isinstance(added, Failure) else next(iter(added.split()), None)
def release_reviewed(tag: str | None, ref: str, cwd: str, after: Release | None = None, run: Git = git) -> bool | Failure:
def release_reviewed(tag: str | None, ref: str, cwd: str, after: Release | None = None, run: Git = git, title: str = templates.TITLE) -> bool | Failure:
"""Whether ref holds a commit titled as a release review opens, `Release review of <release>`: after tag, or anywhere where tag is None.
after is the version a branch with no tag counts as cut, or None. Where it is given, a title counts only where its release is later than after.
Each title is read as its summary in title, the project's `commit-title` template. after is the version a branch with no tag counts as cut, or None. Where it is given, a title counts only where its release is later than after.
"""
titles = run("log", "--format=%s", f"{tag}..{ref}" if tag else ref, cwd=cwd)
if isinstance(titles, Failure):
return titles
reviews = [title.removeprefix("Release review of ") for title in titles.splitlines() if title.startswith("Release review of ")]
summaries = [templates.summary_of(title, line) for line in titles.splitlines()]
reviews = [summary.removeprefix("Release review of ") for summary in summaries if summary.startswith("Release review of ")]
return any(after is None or ((named := parsed(review)) is not None and named > after) for review in reviews)
@@ -164,6 +164,11 @@ class ChunkItem(unittest.TestCase):
self.assertIs(release_standing.release_reviewed(None, "main", repo), True)
self.assertIsInstance(release_standing.release_reviewed("v9.9.9", "main", repo), Failure)
self.assertEqual(release_standing.default_plan(repo, "main", "todo.md", changelog_of(repo)).cut.reviewed, True)
run("tag", "v0.2.0")
run("commit", "-q", "--allow-empty", "-m", "PAY-9 - Release review of 0.3.0")
self.assertIs(release_standing.release_reviewed("v0.2.0", "main", repo), False)
self.assertIs(release_standing.release_reviewed("v0.2.0", "main", repo, title="PAY-{id} - {summary}"), True)
self.assertEqual(release_standing.default_plan(repo, "main", "todo.md", changelog_of(repo), title="PAY-{id} - {summary}").cut.reviewed, True)
def test_counts_no_release_review_of_a_release_cut_under_a_dated_heading_on_a_branch_with_no_tag(self):
repo = tempfile.mkdtemp()
+1 -1
View File
@@ -8,8 +8,8 @@ import typing
from review_rules.round_titles import CAP, COUNTS, EXAMPLE, lacks_counts, OPENING, RELEASE_REVIEW_CAP
from project_config.main import commit_title
from git_cli.git_command import commits
from git_cli.git_repo import git
from run_heavy.capped_docker import finds_this_docker
from git_cli.git_repo import git
from rule_hook.heavy_command import heavy
from command_lines.shell_command import launched, Simple
from review_rules.review_folder import REPORTS
+1 -1
View File
@@ -95,13 +95,13 @@ import sys
from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
from branch_chunks.read import branch_chunks, unsupported
from project_config.main import commit_title, project
from git_cli.git_repo import default_branch, full_history, git, top
from failure import Failure
from score_outcomes.results import file_lines, fixed_later, item_text, misreads, nearest, render, report, Result, results_of
from release_plan.todo_table import item_details, LEVELS, risk, TOP_SCORE
from text_files.markdown_text import listed
from release_plan.named_code import named_files
from project_config.main import commit_title, project
from transcript_archive.location import project_archive
from score_outcomes.reversals import reversal_lines
from record_store.stores import store