Answer architecture round 1: give the transcript archive one module that writes and reads it, anchor the finished line to its stamp, build Reads once, and record the scoring run
This commit is contained in:
+6
-13
@@ -32,7 +32,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from loop_claude.claude_code.entries import assistant_parts, parse_entry, tool_call
|
||||
from failure import Failure
|
||||
from loop_claude.cycle.archive import finished_chunks, FinishedChunk
|
||||
from loop_claude.transcript_archive import finished_chunks, FinishedChunk
|
||||
from loop_claude.paths import paths_from
|
||||
from loop_claude.project.checkout import project_key
|
||||
from shell_reads import Reads, resolved, shell_reads
|
||||
@@ -147,18 +147,11 @@ def measure(threads: list[bytes], checkout: Checkout, home: str) -> Reading | No
|
||||
commit = commit_time(worker)
|
||||
if commit is None:
|
||||
return None
|
||||
tokens = 0
|
||||
reads = Reads([], [])
|
||||
for thread in (worker, *subagents):
|
||||
read_before = [entry for entry in thread if entry.get("type") == "assistant" and str(entry.get("timestamp", "")) < commit]
|
||||
tokens += tokens_in(read_before)
|
||||
for entry in read_before:
|
||||
for part in assistant_parts(entry):
|
||||
found = reads_of(part, str(entry.get("cwd") or "/"), home)
|
||||
reads.read.extend(found.read)
|
||||
reads.added.extend(found.added)
|
||||
roots = [checkout.root, *reads.added]
|
||||
return Reading(tokens, collections.Counter(place for path in reads.read if (place := relative(path, roots)) in checkout.tracked))
|
||||
before = [[entry for entry in thread if entry.get("type") == "assistant" and str(entry.get("timestamp", "")) < commit] for thread in (worker, *subagents)]
|
||||
reads = [reads_of(part, str(entry.get("cwd") or "/"), home) for thread in before for entry in thread for part in assistant_parts(entry)]
|
||||
roots = [checkout.root, *(added for found in reads for added in found.added)]
|
||||
places = collections.Counter(place for found in reads for path in found.read if (place := relative(path, roots)) in checkout.tracked)
|
||||
return Reading(sum(map(tokens_in, before)), places)
|
||||
|
||||
|
||||
def entries_of(raw: bytes) -> list[dict]:
|
||||
|
||||
Reference in New Issue
Block a user