Source code for todowrite.core.types

"""
ToDoWrite Core Type Definitions.

This module contains shared type definitions and utility classes used
throughout the ToDoWrite package.

Key Concepts:
- LayerType: The 12 hierarchical layers from Goal to Command
- StatusType: Workflow states for task tracking
- Metadata: Extensible metadata system
- Command: Executable command definitions

Example:
    >>> from todowrite.core.models import Goal
    >>> from todowrite.core.types import LayerType, Metadata
    >>>
    >>> goal = Goal(
    ...     title="Launch Product",
    ...     description="Successfully launch the new product",
    ...     owner="product-team",
    ...     severity="high"
    ... )
"""

from __future__ import annotations

from typing import Literal

# Define the 12 hierarchical layers in the ToDoWrite system
LayerType = Literal[
    "Goal",
    "Concept",
    "Context",
    "Constraints",
    "Requirements",
    "AcceptanceCriteria",
    "InterfaceContract",
    "Phase",
    "Step",
    "Task",
    "SubTask",
    "Command",
]

# Define workflow status types
StatusType = Literal[
    "planned", "in_progress", "completed", "blocked", "cancelled"
]

# ToDoWrite Core Type Definitions
#
# This module contains shared type definitions and utility classes used
# throughout the ToDoWrite package.
#
# SQLAlchemy model classes are in todowrite.core.models
#
# Available exports:
__all__ = [
    "AcceptanceCriteriaCollection",
    "CommandCollection",
    "LayerType",
    "Metadata",
    "PhaseCollection",
    "StatusType",
    "StepCollection",
    "SubTaskCollection",
    "TaskCollection",
    "ToDoWriteCollection",
]


[docs] class Metadata: """Extensible metadata for ToDoWrite nodes."""
[docs] def __init__( self, owner: str = "", labels: list[str] | None = None, severity: str = "", work_type: str = "", assignee: str = "", extra: dict[str, str | int | bool] | None = None, ) -> None: self.owner = owner self.labels = labels or [] self.severity = severity self.work_type = work_type self.assignee = assignee self.extra = extra or {}
[docs] def to_dict(self) -> dict[str, str | list[str] | int | bool]: """Convert metadata to dictionary.""" return { "owner": self.owner, "labels": self.labels, "severity": self.severity, "work_type": self.work_type, "assignee": self.assignee, **self.extra, }
[docs] class ToDoWriteCollection: """Base collection class for ToDoWrite models."""
[docs] def __init__(self, items: list[str] | None = None) -> None: self.items = items or []
[docs] def all(self) -> list[str]: """Get all items in the collection.""" return self.items
[docs] def size(self) -> int: """Get the size of the collection.""" return len(self.items)
[docs] def empty(self) -> bool: """Check if the collection is empty.""" return len(self.items) == 0
[docs] def exists(self) -> bool: """Check if any items exist in the collection.""" return len(self.items) > 0
[docs] class PhaseCollection(ToDoWriteCollection): """Collection for Phase items.""" pass
[docs] class TaskCollection(ToDoWriteCollection): """Collection for Task items.""" pass
[docs] class AcceptanceCriteriaCollection(ToDoWriteCollection): """Collection for AcceptanceCriteria items.""" pass
[docs] class StepCollection(ToDoWriteCollection): """Collection for Step items.""" pass
[docs] class SubTaskCollection(ToDoWriteCollection): """Collection for SubTask items.""" pass
[docs] class CommandCollection(ToDoWriteCollection): """Collection for Command items.""" pass