Commit d8fb40a6 authored by Jan Reimes's avatar Jan Reimes
Browse files

🔧 feat(workspaces): add workspace directory and sources customization options

parent 607631aa
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

from __future__ import annotations

import shutil

from tdoc_crawler.config import resolve_cache_manager
from tdoc_crawler.config.workspace_registry import WorkspaceRegistry
from tdoc_crawler.logging import get_logger
@@ -33,13 +35,21 @@ def get_workspace(workspace: str | None) -> WorkspaceRegistry | None:
    return registry.get_workspace(normalized_workspace)


def create_workspace(workspace: str | None, auto_build: bool = False, description: str = "") -> WorkspaceRegistry:
def create_workspace(
    workspace: str | None,
    auto_build: bool = False,
    description: str = "",
    workspace_dir: str | None = None,
    sources_dirname: str | None = None,
) -> WorkspaceRegistry:
    """Create a workspace entry after canonical normalization.

    Args:
        workspace: Workspace name to create.
        auto_build: When True, newly added members are automatically processed.
        description: Optional workspace description.
        workspace_dir: Custom workspace data directory path.
        sources_dirname: Custom sources subdirectory name (default: "sources").

    Returns:
        WorkspaceRegistry with created workspace.
@@ -47,7 +57,13 @@ def create_workspace(workspace: str | None, auto_build: bool = False, descriptio
    normalized_workspace = normalize_workspace_name(workspace)
    registry = _get_registry()
    try:
        registry.create_workspace(normalized_workspace, description=description, auto_build=auto_build)
        registry.create_workspace(
            normalized_workspace,
            description=description,
            auto_build=auto_build,
            workspace_dir=workspace_dir,
            sources_dirname=sources_dirname,
        )
        registry.save()
    except ValueError:
        pass  # Workspace already exists
@@ -74,11 +90,12 @@ def list_workspaces() -> list[WorkspaceRegistry]:
    return list(registry.workspaces.values())


def delete_workspace(workspace: str | None) -> bool:
def delete_workspace(workspace: str | None, delete_artifacts: bool = False) -> bool:
    """Delete a workspace.

    Args:
        workspace: Workspace name to delete.
        delete_artifacts: When True, remove workspace directory and files.

    Returns:
        True if deleted, False if not found or if attempting to delete default.
@@ -93,6 +110,16 @@ def delete_workspace(workspace: str | None) -> bool:
        _logger.warning("Workspace '%s' not found — nothing to delete", normalized_workspace)
        return False

    if delete_artifacts:
        try:
            manager = resolve_cache_manager()
            ws_dir = manager.workspace_llm_wiki_dir(normalized_workspace).parent
            if ws_dir.exists():
                shutil.rmtree(ws_dir)
                _logger.info("Deleted workspace artifacts at '%s'", ws_dir)
        except Exception:
            _logger.debug("Skipping artifact deletion: CacheManager not available")

    deleted = registry.delete_workspace(normalized_workspace)
    if not deleted:
        return False