Work in progress: Bash output ceiling and refusing Reads of session transcripts

This commit is contained in:
2026-11-18 08:28:38 +01:00
parent 641645c081
commit a7b2fd0ae1
16 changed files with 274 additions and 114 deletions
+17 -14
View File
@@ -7,6 +7,7 @@ import shutil
import sys
import tempfile
from review_replay.changes import Change
from review_replay.rounds import authored_by, lost_inputs, reviewed_path, Round
from claude_code.reply import claude_reply, Limited
from git_cli.git_repo import default_ref
@@ -21,8 +22,6 @@ from review_rules.review_folder import REPORTS, review_folder
from model_routing.ladder import Rung
from claude_code.entries import structured_output
# Starts claude without its instruction files, as `omitClaudeMd` starts a subagent.
NO_CLAUDE_MD = ["--settings", json.dumps({"env": {"CLAUDE_CODE_DISABLE_CLAUDE_MDS": "1"}})]
MATCH_SCHEMA = {"type": "object", "properties": {"found": {"type": "array", "items": {"type": "integer"}}}, "required": ["found"], "additionalProperties": False}
@@ -76,9 +75,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, bare: bool) -> 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 bare, the replay runs without CLAUDE.md, as `launch` says."""
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, effects, bare))
def findings_replayed(found: Round, code: Code, rung: Rung, project: Rung, home: pathlib.Path, effects: Effects, change: Change | 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."""
reviewed: str | Failure | Limited = first_reply(lambda: review(found, code, rung, home, effects, change))
if isinstance(reviewed, (Failure, Limited)):
return reviewed
return first_reply(lambda: match(found.findings, reviewed, found.root, project, effects))
@@ -92,17 +91,17 @@ 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, bare: bool) -> str | Failure | Limited:
def review(found: Round, code: Code, rung: Rung, home: pathlib.Path, effects: Effects, change: Change | None) -> str | Failure | Limited:
try:
(home / REPORTS).mkdir(mode=0o700, parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix="review-replay-", 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, bare)
return reviewed_in(found, code, rung, Copies(clone, reports), home, 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, bare: bool) -> 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; without CLAUDE.md where bare."""
def reviewed_in(found: Round, code: Code, rung: Rung, copies: Copies, home: pathlib.Path, 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))
copy_reports(found, folder, copies.reports)
prompt = redirected(found.prompt, home, folder, code.path, copies)
@@ -112,7 +111,7 @@ def reviewed_in(found: Round, code: Code, rung: Rung, copies: Copies, home: path
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, bare)
launched = launch(found.reviewer, rung, prompt, found.root, copies, home, change)
if isinstance(launched, Failure):
return launched
reply = claude_reply(effects.claude, launched[0], copies.clone, launched[1], "claude")
@@ -121,10 +120,14 @@ 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, bare: bool) -> 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 bare, it starts without CLAUDE.md, and the prompt holds what the SubagentStart hook and the header's last line hand such a reviewer."""
def launch(reviewer: str, rung: Rung, prompt: str, checkout: str, copies: Copies, home: pathlib.Path, 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 its environment, through its settings; 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 not bare:
if change is None:
return args, prompt
# Another --settings would replace this one, so the whole environment goes in one.
args += ["--settings", json.dumps({"env": change.env})]
if not change.without_instruction_files:
return args, prompt
context = reviewer_context(home)
if isinstance(context, Failure):
@@ -140,7 +143,7 @@ def launch(reviewer: str, rung: Rung, prompt: str, checkout: str, copies: Copies
tracked = config.tracked("working-rules")
# Likewise for an `AGENTS.md` outside the checkout.
rules = config.paths["working-rules"] if tracked is None else pathlib.Path(copies.clone, tracked)
return [*args, *NO_CLAUDE_MD], "\n".join([f"{context}\n\n{prompt}", *([principles] if (principles := principles_line(rules, decisions)) else [])])
return args, "\n".join([f"{context}\n\n{prompt}", *([principles] if (principles := principles_line(rules, decisions)) else [])])
def copy_reports(found: Round, folder: pathlib.Path, reports: str) -> None: