Answer stability round 1: 0 🔴, 5 🟡 (0 misread); read tool results from the API requests Claude Code logs again, test the fields every kind carries, mixed blocks, reads by tool and cwd, and indented or mixed security prompts; drop a cwd fallback that changes no commit found

This commit is contained in:
2026-11-09 00:49:37 +01:00
parent d1ff133941
commit 7a5df16882
6 changed files with 46 additions and 10 deletions
+9 -2
View File
@@ -68,7 +68,7 @@ class AssistantTurn(Entry):
@dataclasses.dataclass(frozen=True, kw_only=True)
class ToolResults(Entry):
"""A "user" entry in which Claude Code returns tool results."""
"""The tool results Claude Code returns in a "user" entry, or logs again with the API request that sent them."""
results: tuple[ToolResult, ...]
@@ -94,6 +94,9 @@ def entry_from(found: dict) -> Entry:
return user_entry(found, carried)
case "cost-state":
return cost_state(found, carried)
# Claude Code logs each API request's last message again, its tool results too, some held nowhere else, so their text counts here: {"type": "api-request-blob", "hash": "…", "message": {"role": "user", "content": [{"type": "tool_result", …}, {"type": "text", …}]}}
case "api-request-blob":
return ToolResults(**carried, results=results_in(found))
if (queued := queued_human_text(found)) is not None:
return HumanTurn(**carried, text=queued)
return Entry(**carried)
@@ -117,7 +120,7 @@ def assistant_turn(found: dict, carried: Carried) -> AssistantTurn:
def user_entry(found: dict, carried: Carried) -> UserText | ToolResults:
if results := tuple(result for block in blocks(found) if (result := tool_result(block))):
if results := results_in(found):
return ToolResults(**carried, results=results)
said = content(found)
text = said if isinstance(said, str) else "".join(part_text(block) or "" for block in blocks(found))
@@ -127,6 +130,10 @@ def user_entry(found: dict, carried: Carried) -> UserText | ToolResults:
return HumanTurn(**carried, text=text) if written_by_human(found) else InjectedText(**carried, text=text)
def results_in(found: dict) -> tuple[ToolResult, ...]:
return tuple(result for block in blocks(found) if (result := tool_result(block)))
# {"type": "cost-state", "totalCostUSD": 40.1, "modelUsage": {"claude-opus-5-5": {"costUSD": 40.1, "outputTokens": 334504, ...}}, ...}
def cost_state(found: dict, carried: Carried) -> CostState:
by_model = found["modelUsage"] if isinstance(found.get("modelUsage"), dict) else {}