Answer architecture round 1: 2 🔴, 2 🟡 (0 misread); move transcript parsing into claude_code and keep repeat_read pure
This commit is contained in:
+13
-3
@@ -37,11 +37,12 @@ import time
|
||||
import typing
|
||||
|
||||
from rule_hook.call import applied, Call, FILE_TOOLS, parsed_call, text
|
||||
from rule_hook.repeat_read import asked_lines, file_lines, repeat_breaches
|
||||
from rule_hook.rules import Breach, check, Checked, command_breaches, file_breaches, rules_help
|
||||
from git_command import commits
|
||||
from claude_code.transcript import current_thread, read_transcript
|
||||
from failure import Failure
|
||||
from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override
|
||||
from rule_hook.repeat_read import repeat_breaches
|
||||
from rule_hook.reviewer_report import report_breaches
|
||||
from rule_hook.reviewer_rung import reviewer_breaches
|
||||
from shell_command import simple_commands
|
||||
@@ -77,9 +78,9 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
|
||||
return text(call.given, "prompt"), text(call.given, "subagent_type"), reviewer_breaches(call, environ)
|
||||
if call.tool == "Bash":
|
||||
command = text(call.given, "command")
|
||||
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + repeat_breaches(call, home)
|
||||
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + read_breaches(call, home)
|
||||
if call.tool == "Read":
|
||||
return "", text(call.given, "file_path"), repeat_breaches(call, home)
|
||||
return "", text(call.given, "file_path"), read_breaches(call, home)
|
||||
path = text(call.given, "file_path")
|
||||
if call.tool not in FILE_TOOLS or not path:
|
||||
return None
|
||||
@@ -110,6 +111,15 @@ def bash_breaches(command: str, cwd: str, home: str) -> list[Breach]:
|
||||
return command_breaches(command, simples, home) + [breach for commit in commits(simples, home) for breach in todo_breaches(commit.directory)]
|
||||
|
||||
|
||||
def read_breaches(call: Call, home: str) -> list[Breach]:
|
||||
"""The repeat-read breaches of a call, read from the asked file and the calling agent's transcript; none where either cannot be read."""
|
||||
asked = asked_lines(call.tool, call.given, call.cwd, home)
|
||||
entries = read_transcript(call.transcript) if asked and call.transcript else []
|
||||
if asked is None or isinstance(entries, Failure) or not entries:
|
||||
return []
|
||||
return repeat_breaches(asked, file_lines(read(asked.path)), current_thread(entries), call.cwd, home)
|
||||
|
||||
|
||||
def read(path: str) -> str:
|
||||
try:
|
||||
return pathlib.Path(path).read_text(encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user