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:
@@ -2,7 +2,7 @@ import dataclasses
|
||||
import typing
|
||||
|
||||
from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, QUOTED_ANSWERS_PER_CYCLE, Ruled, State, transition, WorkerRan, Working
|
||||
from loop_claude.cycle.archive import archive, FINISHED, UNFINISHED
|
||||
from loop_claude.transcript_archive import archive, FINISHED, UNFINISHED
|
||||
from loop_claude.claude_code.session import delete_session, Session, session_open, transcript_file
|
||||
from loop_claude.effects import Effects
|
||||
from failure import Failure
|
||||
|
||||
@@ -14,7 +14,7 @@ from loop_claude.claude_code.session import session_files
|
||||
|
||||
FINISHED = "Verdict: finished"
|
||||
UNFINISHED = "Verdict: unfinished"
|
||||
FINISHED_AT = re.compile(rf"^(\S+) {re.escape(FINISHED)}$", re.MULTILINE)
|
||||
FINISHED_AT = re.compile(rf"^(\d{{4}}-\d\d-\d\dT\d\d:\d\d:\d\dZ) {re.escape(FINISHED)}$", re.MULTILINE)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
+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]:
|
||||
|
||||
+5
-4
@@ -20,15 +20,16 @@ class Reads:
|
||||
|
||||
|
||||
def shell_reads(command: str, cwd: str, home: str) -> Reads:
|
||||
reads = Reads([], [])
|
||||
read: list[str] = []
|
||||
added: list[str] = []
|
||||
base = cwd
|
||||
for tokens in shell_lines(command):
|
||||
for words in segments(tokens):
|
||||
if words[0] == "cd" and len(words) == 2:
|
||||
base = resolved(base, words[1], home)
|
||||
reads.read.extend(resolved(base, word, home) for word in operands(words))
|
||||
reads.added.extend(resolved(base, path, home) for path in worktree_added(words))
|
||||
return reads
|
||||
read += [resolved(base, word, home) for word in operands(words)]
|
||||
added += [resolved(base, path, home) for path in worktree_added(words)]
|
||||
return Reads(read, added)
|
||||
|
||||
|
||||
def shell_lines(command: str) -> typing.Iterator[list[str]]:
|
||||
|
||||
@@ -16,12 +16,13 @@ import uuid
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker
|
||||
from loop_claude import transcript_archive as archive
|
||||
from loop_claude.project import checkout, model_choice, records
|
||||
from loop_claude.effects import Effects
|
||||
from loop_claude.claude_code import entries, session, transcript, trust
|
||||
from failure import Failure
|
||||
from loop_claude.cycle.judge_reply import Finished, Interrupt, QuotedAnswer, Unfinished, verdict_from
|
||||
from loop_claude.cycle import interrupt, judge, retry, run, states, worker
|
||||
from loop_claude.cycle.retry import Limited
|
||||
from loop_claude.loop import main, reload
|
||||
from loop_claude import paths
|
||||
|
||||
@@ -12,7 +12,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from loop_claude.cycle.archive import archive, FINISHED, finished_chunks, FinishedChunk, UNFINISHED
|
||||
from loop_claude.transcript_archive import archive, FINISHED, finished_chunks, FinishedChunk, UNFINISHED
|
||||
from reading_cost import Checkout, Reading
|
||||
from failure import Failure
|
||||
from test_loop_claude_black_box import host_env
|
||||
|
||||
Reference in New Issue
Block a user