import hashlib import pathlib import typing from claude_code.transcript import first_timestamped_line from transcript_archive.project_key import project_key # What an outcomes file's name ends with, in place of its transcript copy's .jsonl. FILE_SUFFIX = ".outcomes.md" def archive_root(home: pathlib.Path, env: typing.Mapping[str, str]) -> pathlib.Path: """Where loop-claude archives every project's chunks.""" return pathlib.Path(env["LOOP_CLAUDE_TRANSCRIPTS"]).expanduser() if env.get("LOOP_CLAUDE_TRANSCRIPTS") else home / ".claude" / "loop-claude-transcripts" def project_archive(checkout_root: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> pathlib.Path: return archive_root(home, env) / project_key(checkout_root, home) def chunk_folder(project_archive: pathlib.Path, transcript: bytes) -> pathlib.Path: # Each chunk's first timestamped line is its own: a finished chunk's session is deleted, so the next chunk's transcript starts afresh. return project_archive / hashlib.sha256(first_timestamped_line(transcript)).hexdigest() def outcomes_of(copy: pathlib.Path) -> pathlib.Path: """The outcomes file beside a transcript copy; transcript_of is its inverse.""" return copy.with_suffix(FILE_SUFFIX) def transcript_of(outcomes: pathlib.Path) -> pathlib.Path: """The transcript copy an outcomes file sits beside; outcomes_of is its inverse.""" return outcomes.with_name(outcomes.name.removesuffix(FILE_SUFFIX) + ".jsonl")