okf-wiki 1.1.1
First public release, published as one snapshot. What changed between versions is in CHANGELOG.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
0fd86a23a3
227 changed files with 96077 additions and 0 deletions
31
okfwiki/transcript.py
Normal file
31
okfwiki/transcript.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""Reads Claude Code session transcripts (.jsonl), as written under ~/.claude/projects/<slug>/. No model call."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
USAGE_FIELDS = ("input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens")
|
||||
|
||||
|
||||
def is_agent_type(recorded: object, name: str) -> bool:
|
||||
"""Whether a subagent's recorded agentType is the agent `name`, started bare ("okf-wiki-reader") or from a
|
||||
plugin, which Claude Code records with the plugin's namespace ("<plugin>:okf-wiki-reader")."""
|
||||
if not isinstance(recorded, str):
|
||||
return False
|
||||
plugin, sep, bare = recorded.rpartition(":")
|
||||
return bare == name and (not sep or bool(plugin))
|
||||
|
||||
|
||||
def read_transcript(path: Path) -> list[dict[str, Any]]:
|
||||
"""Every JSON object line of a transcript; a line that does not parse is skipped."""
|
||||
lines = []
|
||||
for raw in path.read_text(encoding="utf-8").splitlines():
|
||||
try:
|
||||
line = json.loads(raw)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
if isinstance(line, dict):
|
||||
lines.append(line)
|
||||
return lines
|
||||
Loading…
Add table
Add a link
Reference in a new issue