Keep loop-claude's rendering out of the adapter and Claude Code's locations in it
This commit is contained in:
@@ -19,13 +19,17 @@ class UserEntryKind(enum.Enum):
|
||||
SDK_PROMPT = enum.auto()
|
||||
|
||||
|
||||
def locations(home):
|
||||
return {"claude_json": home / ".claude.json", "model_catalog": home / ".claude" / "cache" / "model-catalog", "projects": home / ".claude" / "projects"}
|
||||
|
||||
|
||||
# <projects>/-home-me-code-log/<session id>.jsonl
|
||||
def transcript_path(projects, session_id):
|
||||
hit = glob.glob(os.path.join(glob.escape(str(projects)), "*", f"{session_id}.jsonl"))
|
||||
return hit[0] if hit else ""
|
||||
|
||||
|
||||
# <session id>.jsonl, <session id>/subagents/, <session id>.superseded-1789290815002/
|
||||
# <session id>.jsonl, <session id>/subagents/, and from older versions <session id>.superseded-1789290815002/
|
||||
def session_files(transcript):
|
||||
return glob.glob(glob.escape(transcript.removesuffix(".jsonl")) + "*")
|
||||
|
||||
@@ -39,18 +43,21 @@ def parse(raw):
|
||||
return entry if isinstance(entry, dict) else None
|
||||
|
||||
|
||||
# {"type": "user", "message": {"role": "user", "content": "merge it"}}
|
||||
def content(entry):
|
||||
message = entry.get("message")
|
||||
return message.get("content") if isinstance(message, dict) else None
|
||||
|
||||
|
||||
# {"type": "assistant", "message": {"content": [{"type": "text", "text": "ok"}]}}
|
||||
def parts(entry):
|
||||
found = content(entry)
|
||||
return found if isinstance(found, list) else []
|
||||
|
||||
|
||||
# Alike in the transcript and in stream-json: {"type": "assistant", "message": {"content": [{"type": "text", "text": "ok"}]}}
|
||||
def assistant_parts(entry):
|
||||
return parts(entry) if entry.get("type") == "assistant" else []
|
||||
|
||||
|
||||
def user_entry_kind(entry):
|
||||
# {"type": "user", "isMeta": true, "message": {"content": "<local-command-caveat>Caveat: ..."}}
|
||||
if entry.get("isMeta"):
|
||||
@@ -77,15 +84,14 @@ def typed(entry):
|
||||
return entry.get("type") == "user" and user_entry_kind(entry) is UserEntryKind.HUMAN
|
||||
|
||||
|
||||
# An "assistant" entry's part, alike in the transcript and in stream-json:
|
||||
# {"type": "text", "text": "ok"}, {"type": "tool_use", "name": "Bash", "input": {"command": "echo hi"}}
|
||||
def said(part, limit=400):
|
||||
kind = part.get("type") if isinstance(part, dict) else None
|
||||
if kind == "text" and isinstance(part.get("text"), str) and part["text"].strip():
|
||||
return part["text"]
|
||||
if kind == "tool_use":
|
||||
return f"[tool {part.get('name')}] {json.dumps(part.get('input'))[:limit]}"
|
||||
return ""
|
||||
# {"type": "text", "text": "ok"}
|
||||
def part_text(part):
|
||||
return part["text"] if isinstance(part, dict) and part.get("type") == "text" and isinstance(part.get("text"), str) else None
|
||||
|
||||
|
||||
# {"type": "tool_use", "name": "Bash", "input": {"command": "echo hi"}}
|
||||
def tool_call(part):
|
||||
return (part.get("name"), part.get("input")) if isinstance(part, dict) and part.get("type") == "tool_use" else None
|
||||
|
||||
|
||||
# stream-json's last line: {"type": "result", "subtype": "success", ...}
|
||||
@@ -116,7 +122,6 @@ def mark_trusted(projects, roots):
|
||||
|
||||
|
||||
# <model catalog>/*.json: {"fetchedAt": 1790618085238, "catalog": {"config": {"models": [{"id": "claude-opus-5-5", "name": "Opus 5.5", ...}]}}}
|
||||
# The newest file has the highest fetchedAt.
|
||||
def catalog(folder):
|
||||
newest = {}
|
||||
for path in folder.glob("*.json"):
|
||||
|
||||
Reference in New Issue
Block a user