Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set
CI / tests (pull_request) Successful in 6m34s

This commit is contained in:
2026-12-03 18:56:28 +01:00
parent 20c83f861f
commit 1ca2c8efe0
142 changed files with 1095 additions and 933 deletions
+27 -17
View File
@@ -1,6 +1,7 @@
"""Replay one archived review round on one rung: the code the round reviewed, found again in a throwaway clone, the reviewer's report on it, and the match of that report to the round's archived findings: docs/decisions.md → `routing: a review pass runs below the project's rung only on a rung whose replay of its rounds finds a share of their 🔴 and 🟡 findings no more than a margin below the project's rung's own replay`."""
import dataclasses
import json
from collections.abc import Mapping
import os
import pathlib
import shutil
@@ -18,10 +19,13 @@ from record_store.stores import local_file, store
from project_config.main import located
from review_rules.reviewer_context import principles_line, reviewer_context
from text_files.compressed import read_stored, SUFFIX
from review_rules.review_folder import REPORTS, review_folder
from review_rules.review_folder import reports_folder, review_folder
from model_routing.ladder import Rung
from loop_state.paths import STATE_HOME
from claude_code.entries import structured_output
# Where, under the home folder, the review folders were until 0.18.0: the prompt of a round archived before then names its review folder there.
REPORTS_BEFORE_0_18 = f"{STATE_HOME}/larv-review"
MATCH_SCHEMA = {"type": "object", "properties": {"found": {"type": "array", "items": {"type": "integer"}}}, "required": ["found"], "additionalProperties": False}
@@ -75,9 +79,9 @@ def commit_log(listed: str) -> list[tuple[str, float]]:
return [(commit, float(authored)) for commit, authored in (line.split() for line in listed.splitlines())]
def findings_replayed(found: Round, code: Code, rung: Rung, project: Rung, home: pathlib.Path, effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> set[int] | Failure | Limited:
def findings_replayed(found: Round, code: Code, rung: Rung, project: Rung, home: pathlib.Path, env: Mapping[str, str], effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> set[int] | Failure | Limited:
"""The indexes of the round's findings that its replay on rung reports, as claude on the project's rung matches them, or the Failure of the review or the match; where change is given, the replay runs with it, as `launch` says. The clone is made under scratch, or under the system's temporary folder where it is None."""
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, effects, change, scratch))
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, env, effects, change, scratch))
if isinstance(reviewed, (Failure, Limited)):
return reviewed
return first_reply(lambda: match(found.findings, reviewed, found.root, project, effects))
@@ -91,27 +95,27 @@ class Copies:
# The shell makes and removes the clone itself, and is tested on a temporary home as judge-replay's is.
def review(found: Round, code: Code, rung: Rung, home: pathlib.Path, effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> str | Failure | Limited:
def review(found: Round, code: Code, rung: Rung, home: pathlib.Path, env: Mapping[str, str], effects: Effects, change: Change | None, scratch: pathlib.Path | None) -> str | Failure | Limited:
try:
(home / REPORTS).mkdir(mode=0o700, parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="review-replay-", dir=scratch, ignore_cleanup_errors=True) as clone, tempfile.TemporaryDirectory(prefix="review-replay-", dir=home / REPORTS, ignore_cleanup_errors=True) as reports:
return reviewed_in(found, code, rung, Copies(clone, reports), home, effects, change)
reports_folder(home, env).mkdir(mode=0o700, parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="review-replay-", dir=scratch, ignore_cleanup_errors=True) as clone, tempfile.TemporaryDirectory(prefix="review-replay-", dir=reports_folder(home, env), ignore_cleanup_errors=True) as reports:
return reviewed_in(found, code, rung, Copies(clone, reports), home, env, effects, change)
except OSError as failure:
return Failure(f"could not prepare the replay: {failure}")
def reviewed_in(found: Round, code: Code, rung: Rung, copies: Copies, home: pathlib.Path, effects: Effects, change: Change | None) -> str | Failure | Limited:
def reviewed_in(found: Round, code: Code, rung: Rung, copies: Copies, home: pathlib.Path, env: Mapping[str, str], effects: Effects, change: Change | None) -> str | Failure | Limited:
"""The report of found's reviewer on rung, replayed on code cloned into copies.clone, with its review folder copied into copies.reports; with change where given."""
folder = pathlib.Path(review_folder(str(home), code.path))
folder = pathlib.Path(review_folder(str(home), env, code.path))
copy_reports(found, folder, copies.reports)
prompt = redirected(found.prompt, home, folder, code.path, copies)
prompt = redirected(found.prompt, home, folder, reports_folder(home, env), code.path, copies)
if isinstance(prompt, Failure):
return prompt
if lost := lost_inputs(prompt, copies.reports, lambda name: (pathlib.Path(copies.reports) / name).exists()):
return Failure(f"the prompt names {', '.join(lost)}, which the review folder did not hold from the chunk's start until the round's")
if isinstance(cloned := clone_reviewed(found, code, copies.clone, effects), Failure):
return cloned
launched = launch(found.reviewer, rung, prompt, found.root, copies, home, change)
launched = launch(found.reviewer, rung, prompt, found.root, copies, home, env, change)
if isinstance(launched, Failure):
return launched
reply = claude_reply(effects.claude, launched[0], copies.clone, launched[1], "claude")
@@ -120,7 +124,7 @@ def reviewed_in(found: Round, code: Code, rung: Rung, copies: Copies, home: path
return reply["result"] if isinstance(reply.get("result"), str) else Failure("the reviewer replied with no report")
def launch(reviewer: str, rung: Rung, prompt: str, checkout: str, copies: Copies, home: pathlib.Path, change: Change | None) -> tuple[list[str], str] | Failure:
def launch(reviewer: str, rung: Rung, prompt: str, checkout: str, copies: Copies, home: pathlib.Path, env: Mapping[str, str], change: Change | None) -> tuple[list[str], str] | Failure:
"""claude's arguments and prompt for reviewer on rung, in copies.clone, a copy of the project whose checkout is checkout. Where change is given, claude starts under the environment change holds, which claude's settings set; where change turns the instruction files off, the prompt holds what the SubagentStart hook and the header's last line hand such a reviewer."""
args = ["--agent", reviewer, *rung.flags()]
if change is None:
@@ -132,7 +136,7 @@ def launch(reviewer: str, rung: Rung, prompt: str, checkout: str, copies: Copies
context = reviewer_context(home)
if isinstance(context, Failure):
return context
config = located(checkout, home)
config = located(checkout, home, env)
if isinstance(config, Failure):
return config
record = store(config, "decisions")
@@ -160,12 +164,18 @@ def copy_reports(found: Round, folder: pathlib.Path, reports: str) -> None:
(pathlib.Path(reports) / name).write_bytes(read_stored(folder / name))
def redirected(prompt: str, home: pathlib.Path, folder: pathlib.Path, worktree: str, copies: Copies) -> str | Failure:
"""prompt naming copies.reports in place of the review folder, in either spelling, and copies.clone in place of the worktree; a Failure where it still names the review folder."""
def redirected(prompt: str, home: pathlib.Path, folder: pathlib.Path, reports: pathlib.Path, worktree: str, copies: Copies) -> str | Failure:
"""prompt naming copies.reports in place of the review folder, in each spelling, and copies.clone in place of the worktree; a Failure where it still names a review folder. folder is the chunk's review folder, in the reports folder reports."""
# Replace the folder's path first: outside home it contains the worktree's path, which replacing the worktree's would otherwise turn into the clone's.
prompt = prompt.replace(str(folder), copies.reports).replace(f"~/{folder.relative_to(home)}", copies.reports).replace(worktree, copies.clone)
for root in (reports, home / REPORTS_BEFORE_0_18):
named = root / folder.relative_to(reports)
prompt = prompt.replace(str(named), copies.reports)
if named.is_relative_to(home):
prompt = prompt.replace(f"~/{named.relative_to(home)}", copies.reports)
prompt = prompt.replace(worktree, copies.clone)
# A spelling the rewrite misses, such as $HOME/, would leave the reviewer the live folder and the findings in it.
if REPORTS in prompt.replace(copies.reports, ""):
rest = prompt.replace(copies.reports, "")
if any(spelling in rest for spelling in (REPORTS_BEFORE_0_18, f"{reports.parent.name}/{reports.name}")):
return Failure("the prompt names the review folder in a spelling the replay does not redirect")
return prompt