54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
"""The chunk's review folder, where each reviewer writes its report: skills/larv-review/SKILL.md → "Reports"."""
|
|
import os
|
|
import pathlib
|
|
|
|
from failure import Failure
|
|
from review_rules.round_titles import Findings, reported
|
|
|
|
# Why here: docs/decisions.md → `review: each reviewer under agents/ writes its full report into the chunk's review folder`.
|
|
REPORTS = ".local/state/larv-review"
|
|
|
|
|
|
def review_folder(home: str, worktree: str) -> str:
|
|
"""The review folder of the chunk whose worktree is at worktree: its path relative to home, or to / outside it, under REPORTS."""
|
|
inside = worktree.startswith(home.rstrip("/") + "/")
|
|
return os.path.join(home, REPORTS, os.path.relpath(worktree, home) if inside else worktree.lstrip("/"))
|
|
|
|
|
|
def made_review_folder(worktree: str, home: pathlib.Path) -> pathlib.Path | Failure:
|
|
"""Makes the review folder of the chunk whose worktree is at worktree, leaving REPORTS readable by the user alone, and returns its path."""
|
|
folder = pathlib.Path(review_folder(str(home), worktree))
|
|
try:
|
|
(home / REPORTS).mkdir(parents=True, exist_ok=True)
|
|
(home / REPORTS).chmod(0o700)
|
|
folder.mkdir(parents=True, exist_ok=True)
|
|
except OSError as failure:
|
|
return Failure(f"could not make the review folder {folder}: {failure}")
|
|
return folder
|
|
|
|
|
|
def round_report(folder: pathlib.Path, pass_: str, round_: int) -> pathlib.Path:
|
|
"""The report of pass_'s round round_ in the review folder, which asks for the rerun one rung up where there is one."""
|
|
return folder / f"{pass_}-round-{round_}.md"
|
|
|
|
|
|
def rerun_report(asked: pathlib.Path) -> pathlib.Path:
|
|
"""The report of the rerun one rung up that the report asked asks for, which stands in its place."""
|
|
return asked.with_name(asked.stem + "-rerun.md")
|
|
|
|
|
|
def standing_report(folder: pathlib.Path, pass_: str, round_: int) -> pathlib.Path:
|
|
"""The report that stands for pass_'s round round_ in the review folder: the rerun's where there is one, else the round's."""
|
|
asked = round_report(folder, pass_, round_)
|
|
return rerun_report(asked) if rerun_report(asked).exists() else asked
|
|
|
|
|
|
def findings_in(report: pathlib.Path) -> Findings | Failure:
|
|
"""The findings a round's report gives, as round_titles.reported counts them."""
|
|
try:
|
|
return reported(report.read_text(encoding="utf-8"))
|
|
except FileNotFoundError:
|
|
return Failure(f"no report at {report}")
|
|
except (OSError, UnicodeDecodeError) as failure:
|
|
return Failure(f"could not read {report}: {failure}")
|