"""ConversationRepository - an object-shaped, atomic-write-backed facade over ``core/history.py`` (R06-T02). Same rationale as ``workspace_repository_impl.py``: the module-level functions in ``core/history.py`` are still what production code calls (they now write atomically themselves), this class is the seam for application-layer code that wants an object instead of a directory-parameterised function. """ from __future__ import annotations from pathlib import Path from typing import Any, Dict, List, Optional from cowork_local.config import HISTORY_DIR from cowork_local.core.history import ( delete_conversation, list_conversations, load_conversation, new_session_id, rename_conversation, save_conversation, set_pinned, ) class ConversationRepository: """CRUD + search over conversation JSON files, scoped to one ``directory`` (defaults to the app's real ``HISTORY_DIR``).""" def __init__(self, directory: Optional[Path] = None) -> None: self._directory = Path(directory) if directory is not None else HISTORY_DIR def new_session_id(self) -> str: return new_session_id() def save(self, kind: str, session_id: str, messages: List[Dict[str, Any]], **kwargs) -> Path: return save_conversation(self._directory, kind, session_id, messages, **kwargs) def load(self, path: Path) -> Dict[str, Any]: return load_conversation(path) def list(self, query: str = "") -> List[Dict[str, Any]]: return list_conversations(self._directory, query) def delete(self, path: Path) -> None: delete_conversation(path) def rename(self, path: Path, new_title: str) -> None: rename_conversation(path, new_title) def set_pinned(self, path: Path, pinned: bool) -> None: set_pinned(path, pinned) __all__ = ["ConversationRepository"]