Files
ThothII/harness/tht/session/repository.py
T

44 lines
1.5 KiB
Python

"""Storage contract for the durable, user-owned session workflow state."""
from __future__ import annotations
from typing import Protocol, Sequence
from tht.decisions import DecisionInput, DecisionRecord
from tht.session.models import PrincipalContext, SessionManifest, SessionSnapshot
class SessionRepository(Protocol):
"""Persistence boundary shared by local files and the server database adapter."""
principal: PrincipalContext
def create(self, manifest: SessionManifest) -> SessionSnapshot: ...
def get(self, session_id: str) -> SessionSnapshot: ...
def save_manifest(self, manifest: SessionManifest) -> SessionSnapshot: ...
def read_artifact(self, session_id: str, key: str) -> str | None: ...
def write_artifact(self, session_id: str, key: str, content: str) -> None: ...
def append_decisions(
self, session_id: str, decisions: Sequence[DecisionInput | dict]
) -> list[DecisionRecord]: ...
def get_preferences(self) -> dict: ...
def set_preferences(self, preferences: dict) -> None: ...
def delete(self, session_id: str) -> None: ...
def build_session_repository(config, principal: PrincipalContext, *, home=None) -> SessionRepository:
"""Build the local adapter for Task 1; server selection arrives with Task 2."""
from tht.config import local_tht_home
from tht.session.filesystem_repository import FilesystemSessionRepository
workspace = getattr(config, "_workspace_id", "default")
return FilesystemSessionRepository(home or local_tht_home(), workspace, principal)