"""Task model.""" from sqlalchemy import ( Column, String, Integer, Text, DateTime, ForeignKey, Boolean, JSON ) from app.models.base import Base, TimestampMixin, TenantMixin class Task(Base, TimestampMixin, TenantMixin): """A task is a work unit within a project. Can be assigned to a human user or an AI Worker. Status: pending -> assigned -> in_progress -> review -> done -> rejected -> cancelled Priority: low, medium, high, urgent """ __tablename__ = "tasks" id = Column(Integer, primary_key=True, autoincrement=True) project_id = Column(Integer, ForeignKey("projects.id"), nullable=False, index=True) title = Column(String(500), nullable=False) description = Column(Text, default="") status = Column(String(50), nullable=False, default="pending") priority = Column(String(20), nullable=False, default="medium") # Assignment: assignee is a User (human or AI-linked) assignee_id = Column(Integer, ForeignKey("users.id"), nullable=True) # If assigned to AI, which worker profile worker_id = Column(Integer, ForeignKey("ai_workers.id"), nullable=True) # Task type: single_call, agent_loop, multi_agent (MVP: single_call + agent_loop) task_type = Column(String(50), default="single_call") # Task input (prompt, context, parameters) input_data = Column(Text, default="") # JSON string with prompt/context output_data = Column(Text, nullable=True) # JSON string with result # HITL: does this task require human review? requires_review = Column(Boolean, default=True) review_status = Column(String(50), nullable=True) # pending, approved, rejected # Cost tracking token_cost_estimate = Column(Integer, nullable=True) # Dependencies (list of task IDs that must complete first) depends_on = Column(Text, default="[]") # JSON array # Timeline due_date = Column(DateTime, nullable=True) started_at = Column(DateTime, nullable=True) completed_at = Column(DateTime, nullable=True) # Execution metadata (retries, duration, etc.) execution_meta = Column(Text, default="{}") # JSON def __repr__(self): return f""