Answer principles round 1: 0 🔴, 5 🟡 (0 misread); make a move a union with ToStatus, take only parsed events in figures, catch OSError at each file operation, pass progress through the bench, type the sides, and split the README bullet
CI / tests (pull_request) Successful in 5m4s

This commit is contained in:
2026-11-23 01:37:39 +01:00
parent 9fe060575b
commit cfe537b3fd
11 changed files with 186 additions and 123 deletions
+8 -7
View File
@@ -3,7 +3,7 @@ import dataclasses
import statistics
import typing
from claude_code.entries import Entry, json_object, tool_calls, ToolCall
from claude_code.entries import Entry, entry_from, tool_calls, ToolCall
from failure import Failure
from task_bench.runs import HOME, WORK
from reading_cost.measure import reads_of
@@ -11,7 +11,9 @@ from claude_code.tokens import Tokens, tokens_of
# The tools that read or search without a shell. A Bash call counts where `reads_of` finds a file it reads.
READING_TOOLS = frozenset({"Glob", "Grep", "Read"})
SIDES = ("base", "head")
# A bench's two sides: the commit before the change and the one after it.
Side = typing.Literal["base", "head"]
SIDES: tuple[Side, Side] = ("base", "head")
@dataclasses.dataclass(frozen=True)
@@ -31,7 +33,7 @@ class Result(typing.NamedTuple):
holds what its stream tells, for the digest."""
task: int
side: str
side: Side
run: int
passed: bool
figures: Figures | None
@@ -60,13 +62,12 @@ COLUMNS = (
HEADINGS = ["Bug", "Side", "Passed", *(column.heading for column in COLUMNS)]
def figures(stream: bytes, entries: typing.Sequence[Entry], bug_file: str) -> Figures | None | Failure:
"""The figures of the run whose claude printed stream, which parses into entries, with bug_file the bug's file as the run's
def figures(events: list[dict], bug_file: str) -> Figures | None | Failure:
"""The figures of the run whose claude printed events, its stream's JSON lines, with bug_file the bug's file as the run's
container names it.
None where the stream holds no result. A Failure where the API refused the run, as on a token it doesn't take: such a run
doesn't measure anything, and every later run would end the same."""
events = [event for line in stream.splitlines() if (event := json_object(line))]
result = next((event for event in reversed(events) if event.get("type") == "result"), None)
if result is None:
return None
@@ -75,7 +76,7 @@ def figures(stream: bytes, entries: typing.Sequence[Entry], bug_file: str) -> Fi
return Failure(f"claude could not use the API: {result.get('result')}")
# {"type": "system", "subtype": "init", "model": "claude-haiku-5-5", "claude_code_version": "2.1.330", ...}
init = next((event for event in events if event.get("subtype") == "init"), {})
calls = [call for _, call in tool_calls(entries)]
calls = [call for _, call in tool_calls([entry_from(event) for event in events])]
return Figures(str(init.get("claude_code_version", "")), str(init.get("model", "")), tokens_of(result.get("usage")), int(result.get("num_turns") or 0), (result.get("duration_ms") or 0) / 1000, reads_before(calls, bug_file))