Group loop_claude's modules into claude_code, claude_runs and project, and move the findings document beside larv-review
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import json
|
||||
|
||||
from loop_claude.claude_code.formats import assistant_parts, human_text, parse, part_text, tool_call
|
||||
from loop_claude.outcome import Failure
|
||||
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
with open(path, "rb") as handle:
|
||||
return [entry for raw in handle if (entry := parse(raw))]
|
||||
except OSError as failure:
|
||||
return Failure(f"could not read the transcript {path}: {failure.strerror}")
|
||||
|
||||
|
||||
def human_turns(entries):
|
||||
return sum(1 for entry in entries if human_text(entry) is not None)
|
||||
|
||||
|
||||
def render(entries):
|
||||
lines = []
|
||||
for entry in entries:
|
||||
lines += [line for part in assistant_parts(entry) if (line := part_line(part))]
|
||||
if (text := human_text(entry)) is not None:
|
||||
lines.append("[human] " + text)
|
||||
return "\n\n".join(lines)
|
||||
|
||||
|
||||
def part_line(part, limit=400):
|
||||
if (text := part_text(part)) and text.strip():
|
||||
return text
|
||||
if call := tool_call(part):
|
||||
name, arguments = call
|
||||
return f"[tool {name}] {json.dumps(arguments)[:limit]}"
|
||||
return ""
|
||||
Reference in New Issue
Block a user