Kairo-Jinkendo/backend/steering/strategies/next_action/sequential_dependency.py

53 lines
1.5 KiB
Python
Raw Permalink Normal View History

"""Sequential dependency NextAction strategy — AP2.0d / Spec-D D6."""
from __future__ import annotations
from typing import Any
from steering.strategies.next_action.default_strategy import DefaultNextActionStrategy
from steering.strategies.next_action.execution_ready import (
first_active_gate_id,
list_execution_ready_candidates,
)
from steering.strategies.next_action.registry import (
get_next_action_strategy,
register_next_action_strategy,
)
from tenant_context import TenantContext
_default = DefaultNextActionStrategy()
class SequentialDependencyStrategy:
key = "sequential_dependency"
def evaluate(
self,
ctx: TenantContext,
*,
initiative_id: str | None = None,
limit: int = 10,
) -> list[dict[str, Any]]:
if limit < 1:
limit = 1
if not initiative_id:
return _default.evaluate(ctx, limit=limit)
gate_scope = first_active_gate_id(ctx, initiative_id)
ready = list_execution_ready_candidates(
ctx,
initiative_id,
limit=limit,
scope_roadmap_item_id=gate_scope,
prefer_critical_path=True,
)
return ready[:limit]
sequential_dependency_strategy = SequentialDependencyStrategy()
def register_sequential_dependency_strategy() -> None:
if not get_next_action_strategy(sequential_dependency_strategy.key):
register_next_action_strategy(sequential_dependency_strategy)