"""WorkspaceRepository - an object-shaped, atomic-write-backed facade over ``core/projects.py`` (R06-T02). ``core/projects.py``'s module-level functions (``list_projects``, ``load_project``, ``save_project``, ``new_project``, ``delete_project``) are still what every existing call site (``ui/workspace_tab.py``, ``state.py``, task executors) uses, and stay that way - they now write through :func:`atomic_write.write_json` themselves, so the durability fix applies whether or not a caller ever touches this class. This repository exists for the application layer (``application/workspaces``, R06-T05) to depend on an interface instead of reaching into ``core/`` - useful once code above ``core/`` starts being written against ``domain``/``application`` seams instead of the legacy module functions. It is a thin pass-through today, not a re-implementation: same on-disk format, same directory, same functions underneath. """ from __future__ import annotations from pathlib import Path from typing import List, Optional from cowork_local.core.projects import ( PROJECTS_DIR, Project, delete_project, list_projects, load_project, new_project, save_project, ) class WorkspaceRepository: """CRUD over :class:`~cowork_local.core.projects.Project`, scoped to one ``directory`` (defaults to the app's real ``PROJECTS_DIR``; tests pass a ``tmp_path`` so nothing touches the user's real config folder).""" def __init__(self, directory: Optional[Path] = None) -> None: self._directory = directory or PROJECTS_DIR def list(self) -> List[Project]: return list_projects(self._directory) def get(self, project_id: str) -> Optional[Project]: return load_project(project_id, self._directory) def save(self, project: Project) -> Path: return save_project(project, self._directory) def create(self, name: str, description: str = "", instructions: str = "", output_dir: str = "") -> Project: return new_project(name, description, instructions, output_dir, self._directory) def delete(self, project_id: str) -> bool: return delete_project(project_id, self._directory) __all__ = ["WorkspaceRepository"]