2026-06-22 13:52:13 +02:00
|
|
|
import uuid
|
|
|
|
|
from datetime import date, datetime
|
|
|
|
|
from typing import Literal
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict, field_validator
|
|
|
|
|
|
|
|
|
|
from api.schemas.workplan_dependency import WorkplanDepStub
|
2026-09-14 15:28:58 +02:00
|
|
|
from api.work_record_flavor import (
|
|
|
|
|
FLAVOR_PROMOTION_REASONS,
|
|
|
|
|
WORK_RECORD_FLAVORS,
|
|
|
|
|
normalize_flavor,
|
|
|
|
|
normalize_promotion_reason,
|
|
|
|
|
)
|
2026-06-22 13:52:13 +02:00
|
|
|
from api.workplan_status import normalize_workplan_status
|
|
|
|
|
|
|
|
|
|
WorkplanStatus = Literal[
|
|
|
|
|
"proposed",
|
|
|
|
|
"ready",
|
|
|
|
|
"active",
|
|
|
|
|
"blocked",
|
|
|
|
|
"backlog",
|
|
|
|
|
"finished",
|
|
|
|
|
"archived",
|
|
|
|
|
]
|
|
|
|
|
ExecutionState = Literal["manual", "queued", "scheduled", "launching", "paused", "completed", "cancelled"]
|
|
|
|
|
LaunchMode = Literal["manual", "queued", "scheduled", "immediate"]
|
|
|
|
|
ConcurrencyMode = Literal["sequential", "parallel"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkplanStatusMixin(BaseModel):
|
|
|
|
|
@field_validator("status", mode="before", check_fields=False)
|
|
|
|
|
@classmethod
|
|
|
|
|
def _normalise_status(cls, value):
|
|
|
|
|
return normalize_workplan_status(value)
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 15:28:58 +02:00
|
|
|
class WorkplanFlavorMixin(BaseModel):
|
|
|
|
|
@field_validator("flavor", mode="before", check_fields=False)
|
|
|
|
|
@classmethod
|
|
|
|
|
def _normalise_flavor(cls, value):
|
|
|
|
|
flavor = normalize_flavor(value)
|
|
|
|
|
if flavor is not None and flavor not in WORK_RECORD_FLAVORS:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"Unknown work-record flavor {flavor!r}; "
|
|
|
|
|
f"expected one of {', '.join(WORK_RECORD_FLAVORS)}"
|
|
|
|
|
)
|
|
|
|
|
return flavor
|
|
|
|
|
|
|
|
|
|
@field_validator("flavor_promotion_reason", mode="before", check_fields=False)
|
|
|
|
|
@classmethod
|
|
|
|
|
def _normalise_promotion_reason(cls, value):
|
|
|
|
|
reason = normalize_promotion_reason(value)
|
|
|
|
|
if reason is not None and reason not in FLAVOR_PROMOTION_REASONS:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"Unknown flavor_promotion_reason {reason!r}; "
|
|
|
|
|
f"expected one of {', '.join(FLAVOR_PROMOTION_REASONS)}"
|
|
|
|
|
)
|
|
|
|
|
return reason
|
|
|
|
|
|
|
|
|
|
@field_validator("flavor_promoted_from", mode="before", check_fields=False)
|
|
|
|
|
@classmethod
|
|
|
|
|
def _normalise_promoted_from(cls, value):
|
|
|
|
|
flavor = normalize_flavor(value)
|
|
|
|
|
if flavor is not None and flavor not in WORK_RECORD_FLAVORS:
|
|
|
|
|
raise ValueError(
|
|
|
|
|
f"Unknown flavor_promoted_from {flavor!r}; "
|
|
|
|
|
f"expected one of {', '.join(WORK_RECORD_FLAVORS)}"
|
|
|
|
|
)
|
|
|
|
|
return flavor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkplanCreate(WorkplanStatusMixin, WorkplanFlavorMixin):
|
2026-08-22 09:43:55 +02:00
|
|
|
id: uuid.UUID | None = None
|
2026-06-22 13:52:13 +02:00
|
|
|
repo_id: uuid.UUID
|
|
|
|
|
topic_id: uuid.UUID | None = None
|
|
|
|
|
slug: str
|
|
|
|
|
title: str
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: WorkplanStatus = "active"
|
|
|
|
|
owner: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
planning_priority: str | None = None
|
|
|
|
|
planning_order: int | None = None
|
2026-09-14 15:28:58 +02:00
|
|
|
flavor: str | None = None
|
|
|
|
|
flavor_promotion_reason: str | None = None
|
|
|
|
|
flavor_promoted_from: str | None = None
|
2026-06-22 13:52:13 +02:00
|
|
|
execution_state: ExecutionState = "manual"
|
|
|
|
|
launch_mode: LaunchMode = "manual"
|
|
|
|
|
concurrency_mode: ConcurrencyMode = "sequential"
|
|
|
|
|
queue_rank: int | None = None
|
|
|
|
|
execution_group: str | None = None
|
|
|
|
|
scheduled_for: datetime | None = None
|
|
|
|
|
repo_goal_id: uuid.UUID | None = None
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 15:28:58 +02:00
|
|
|
class WorkplanUpdate(WorkplanStatusMixin, WorkplanFlavorMixin):
|
2026-06-22 13:52:13 +02:00
|
|
|
title: str | None = None
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: WorkplanStatus | None = None
|
|
|
|
|
owner: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
planning_priority: str | None = None
|
|
|
|
|
planning_order: int | None = None
|
2026-09-14 15:28:58 +02:00
|
|
|
flavor: str | None = None
|
|
|
|
|
flavor_promotion_reason: str | None = None
|
|
|
|
|
flavor_promoted_from: str | None = None
|
2026-06-22 13:52:13 +02:00
|
|
|
execution_state: ExecutionState | None = None
|
|
|
|
|
launch_mode: LaunchMode | None = None
|
|
|
|
|
concurrency_mode: ConcurrencyMode | None = None
|
|
|
|
|
queue_rank: int | None = None
|
|
|
|
|
execution_group: str | None = None
|
|
|
|
|
scheduled_for: datetime | None = None
|
|
|
|
|
topic_id: uuid.UUID | None = None
|
|
|
|
|
repo_id: uuid.UUID | None = None
|
|
|
|
|
repo_goal_id: uuid.UUID | None = None
|
|
|
|
|
|
|
|
|
|
|
2026-07-04 00:42:56 +02:00
|
|
|
class WorkplanFileBinding(BaseModel):
|
|
|
|
|
workplan_id: uuid.UUID
|
|
|
|
|
filename: str
|
|
|
|
|
relative_path: str
|
|
|
|
|
repo_slug: str
|
|
|
|
|
archived: bool = False
|
|
|
|
|
status: WorkplanStatus | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkplanBindingsSync(BaseModel):
|
|
|
|
|
bindings: list[WorkplanFileBinding]
|
|
|
|
|
|
|
|
|
|
|
2026-06-22 13:52:13 +02:00
|
|
|
class WorkplanRead(WorkplanStatusMixin):
|
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
id: uuid.UUID
|
|
|
|
|
repo_id: uuid.UUID
|
|
|
|
|
topic_id: uuid.UUID | None = None
|
|
|
|
|
repo_goal_id: uuid.UUID | None = None
|
|
|
|
|
slug: str
|
|
|
|
|
title: str
|
|
|
|
|
description: str | None = None
|
|
|
|
|
status: WorkplanStatus
|
|
|
|
|
owner: str | None = None
|
|
|
|
|
due_date: date | None = None
|
|
|
|
|
planning_priority: str | None = None
|
|
|
|
|
planning_order: int | None = None
|
2026-09-14 15:28:58 +02:00
|
|
|
flavor: str | None = None
|
|
|
|
|
flavor_promotion_reason: str | None = None
|
|
|
|
|
flavor_promoted_from: str | None = None
|
2026-06-22 13:52:13 +02:00
|
|
|
execution_state: ExecutionState = "manual"
|
|
|
|
|
launch_mode: LaunchMode = "manual"
|
|
|
|
|
concurrency_mode: ConcurrencyMode = "sequential"
|
|
|
|
|
queue_rank: int | None = None
|
|
|
|
|
execution_group: str | None = None
|
|
|
|
|
scheduled_for: datetime | None = None
|
2026-07-04 00:42:56 +02:00
|
|
|
backing_filename: str | None = None
|
|
|
|
|
backing_relative_path: str | None = None
|
|
|
|
|
backing_archived: bool | None = None
|
|
|
|
|
backing_synced_at: datetime | None = None
|
CUST-WP-0074-T02: task wait qualifiers in the hub read model
Adds tasks.decision_id and workplan_dependencies.from_task_id (migration
e8f9a0b1c2d3). A from_task_id column is needed rather than
from_workplan_id plus description: the partial unique indexes key on
(from_workplan_id, target, relationship_type), so two tasks in one
workplan waiting on the same target could not both be indexed, and the
derived wait_kind needs per-task attribution. The two existing unique
indexes are narrowed to frontmatter edges (from_task_id IS NULL) and two
task-origin counterparts are added; downgrade deletes task-origin rows
before restoring the old indexes.
POST /workplans/{id}/dependencies/ accepts from_task_id (must belong to
the from workplan; a task cannot depend on itself). TaskCreate/Update/Read
carry decision_id.
Derived read-model fields, no new write routes (rule 5):
- TaskRead.wait_kind: external | human | both | unqualified, null unless
status is wait (dependency rows from this task / needs_human).
- WorkplanRead.blocked_kind: human | external | none, null unless status
is blocked. Human wins over external.
Both come from api/services/wait_kind.py, applied on GET /tasks/,
GET /tasks/{id}, GET /workplans/ and GET /workplans/{id}.
The identifier-migration reference-count proof now includes from_task_id
(FK count guard 22 -> 23).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Assistant: claude-code
Assistant-Model: sonnet
Assistant-Process: 237582@bnt-lap001
Assistant-Session: f2b3d9f1-8fb9-4b9c-bc2b-837ec5dfc826
2026-09-28 22:39:18 +02:00
|
|
|
# Derived (CUST-WP-0074 rule 5): "human" | "external" | "none" while
|
|
|
|
|
# status is blocked, else None. Set by
|
|
|
|
|
# api.services.wait_kind.annotate_workplans on read routes.
|
|
|
|
|
blocked_kind: str | None = None
|
2026-06-22 13:52:13 +02:00
|
|
|
created_at: datetime
|
|
|
|
|
updated_at: datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkplanWithTaskCounts(WorkplanRead):
|
|
|
|
|
tasks_total: int = 0
|
|
|
|
|
tasks_wait: int = 0
|
|
|
|
|
tasks_todo: int = 0
|
|
|
|
|
tasks_progress: int = 0
|
|
|
|
|
tasks_done: int = 0
|
|
|
|
|
tasks_cancel: int = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkplanWithDeps(WorkplanWithTaskCounts):
|
|
|
|
|
"""WorkplanWithTaskCounts enriched with dependency graph edges."""
|
|
|
|
|
depends_on: list[WorkplanDepStub] = []
|
|
|
|
|
blocks: list[WorkplanDepStub] = []
|
2026-08-22 09:43:55 +02:00
|
|
|
blocked_reasons: list[dict] = []
|