diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index 635bf494..50138367 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -1,5 +1,4 @@ """Every Claude Code format loop-claude reads, each under a sample of it, as Claude Code 2.1.284 writes it.""" -import enum import glob import json import os @@ -7,18 +6,6 @@ import os from loop_claude.outcome import Failure -class UserEntryKind(enum.Enum): - """Who wrote a "user" entry: the human wrote HUMAN, Claude Code every other kind.""" - - COMMAND = enum.auto() - CTRL_C = enum.auto() - EMPTY = enum.auto() - HUMAN = enum.auto() - META = enum.auto() - NON_TEXT = enum.auto() - SDK_PROMPT = enum.auto() - - def locations(home): return home / ".claude.json", home / ".claude" / "cache" / "model-catalog", home / ".claude" / "projects" @@ -57,36 +44,29 @@ def assistant_parts(entry): return parts(entry) if entry.get("type") == "assistant" else [] -def user_entry_kind(entry): +def written_by_human(entry): + """Whether the human wrote a "user" entry; Claude Code writes the rest.""" # {"type": "user", "isMeta": true, "message": {"content": "Caveat: ..."}} - if entry.get("isMeta"): - return UserEntryKind.META # {"type": "user", "promptSource": "sdk", "message": {"content": "Continue the task; ..."}} - if entry.get("promptSource") == "sdk": - return UserEntryKind.SDK_PROMPT + if entry.get("isMeta") or entry.get("promptSource") == "sdk": + return False # {"type": "user", "message": {"content": "/model\n..."}} # {"type": "user", "promptSource": "system", "message": {"content": "..."}} # {"type": "user", "promptSource": "typed", "message": {"content": "merge it"}} if isinstance(text := content(entry), str): source = entry.get("promptSource") - return UserEntryKind.COMMAND if source == "system" or (source != "typed" and text.startswith("<")) else UserEntryKind.HUMAN + return source != "system" and (source == "typed" or not text.startswith("<")) texts = [part_text(part) for part in parts(entry)] - if not texts: - return UserEntryKind.EMPTY # {"type": "user", "message": {"content": [{"tool_use_id": "toolu_01…", "type": "tool_result", "content": "hi"}]}} - if None in texts: - return UserEntryKind.NON_TEXT # {"type": "user", "message": {"content": [{"type": "text", "text": "[Request interrupted by user]"}]}} - if any(text.startswith("[Request interrupted") for text in texts): - return UserEntryKind.CTRL_C - return UserEntryKind.HUMAN + return bool(texts) and None not in texts and not any(text.startswith("[Request interrupted") for text in texts) def human_text(entry): """What the human wrote in the entry, or None where Claude Code wrote it.""" if (queued := queued_human_text(entry)) is not None: return queued - if entry.get("type") != "user" or user_entry_kind(entry) is not UserEntryKind.HUMAN: + if entry.get("type") != "user" or not written_by_human(entry): return None text = content(entry) return text if isinstance(text, str) else "".join(part_text(part) or "" for part in parts(entry)) diff --git a/todo.md b/todo.md index bd55ee40..2087f0a2 100644 --- a/todo.md +++ b/todo.md @@ -8,10 +8,9 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens The places the panel on `rebuild` at 2f9ab2f named (`docs/decisions.md`), capping dimension first: -- **Keep in `UserEntryKind` only the kinds a caller tells apart.** Three seats: `human_text` compares only `HUMAN`, and they hunted for the caller of the other six. - **Keep `formats.py` to Claude Code's shapes: `locations` into `paths.py`, `catalog`'s file reads out.** Three seats found paths and I/O in a file named for formats. - **Group `bin/loop_claude/`'s top-level modules, and name `claude_runs` apart from `claude_code`.** Two seats: eleven modules of mixed altitude side by side. -- **Say at `user_entry_kind` why a `<` prefix marks Claude Code's own entry, and at `trust` why a failure only warns.** Three seats found either only in `CHANGELOG.md`. +- **Say at `written_by_human` why a `<` prefix marks Claude Code's own entry, and at `trust` why a failure only warns.** Three seats found either only in `CHANGELOG.md`. - **Say in the README why the tests run on the host and need `uv`.** Two seats: `CLAUDE.md` says never run a runtime on the host, and only `test_python_floor.py` says what `uv` is for. - **Score `rebuild` with the four-seat panel at 7.0 or above on every dimension and the overall, none below the last run, and open its PR into main for the human.** ⚠️ Leave that PR ready and unmerged: only the human merges it, after approving the whole rebuild. A dimension under the floor gets its places filed above this item.