40 lines
972 B
Python
40 lines
972 B
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
|
|
name: str
|
|
projects: pathlib.Path
|
|
|
|
|
|
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(uuid.uuid5(NAMESPACE, name), name, paths.projects)
|
|
|
|
|
|
def transcript_file(session):
|
|
return transcript_path(session.projects, 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)
|