40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
import dataclasses
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import sys
|
|
import uuid
|
|
|
|
from loop_claude.claude_code.formats import session_files, transcript_path
|
|
|
|
NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec")
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class Session:
|
|
id: uuid.UUID
|
|
claude_code_transcripts: pathlib.Path
|
|
name: str
|
|
|
|
|
|
def session_for(project, paths):
|
|
"""Exists while its transcript does."""
|
|
# "A " is the human's cue in the session picker that the session is the loop's.
|
|
name = f"A {project} loop-claude"
|
|
return Session(id=uuid.uuid5(NAMESPACE, name), claude_code_transcripts=paths.claude_code_transcripts, name=name)
|
|
|
|
|
|
def transcript_file(session):
|
|
return transcript_path(session.claude_code_transcripts, session.id)
|
|
|
|
|
|
def delete_session(session):
|
|
path = transcript_file(session)
|
|
if not path:
|
|
return
|
|
for sibling in session_files(path):
|
|
try:
|
|
shutil.rmtree(sibling) if os.path.isdir(sibling) else os.remove(sibling)
|
|
except OSError as failure:
|
|
print(f"could not remove {sibling}: {failure}", file=sys.stderr)
|