AP1.1: Method Registry — product_milestone_driven + Methode wählbar
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 1m23s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 1m23s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s
Zweite Built-in-Methode mit meilensteinorientierter NextAction-Strategie, API und UI-Auswahl pro Vorhaben; AP0.10d Validation-Vorlagen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
95feba6204
commit
fc956d4ceb
27 files changed
+684
-15
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,18 @@
|
||||
"""Bootstrap NextAction strategies."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from steering.strategies.next_action.default_strategy import default_strategy
|
||||
from steering.strategies.next_action.product_milestone_driven import (
|
||||
product_milestone_strategy,
|
||||
)
|
||||
from steering.strategies.next_action.registry import (
|
||||
get_next_action_strategy,
|
||||
register_next_action_strategy,
|
||||
)
|
||||
|
||||
|
||||
def register_builtin_strategies() -> None:
|
||||
for strategy in (default_strategy, product_milestone_strategy):
|
||||
if not get_next_action_strategy(strategy.key):
|
||||
register_next_action_strategy(strategy)
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Default NextAction strategy — delegates to global rules (AP1.0)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from steering.signals import default_rules
|
||||
from tenant_context import TenantContext
|
||||
|
||||
|
||||
class DefaultNextActionStrategy:
|
||||
key = "default"
|
||||
|
||||
def evaluate(
|
||||
self,
|
||||
ctx: TenantContext,
|
||||
*,
|
||||
initiative_id: str | None = None,
|
||||
limit: int = 10,
|
||||
) -> list[dict[str, Any]]:
|
||||
if initiative_id:
|
||||
return default_rules.get_next_action_candidates_for_initiative(
|
||||
ctx, initiative_id=initiative_id, limit=limit
|
||||
)
|
||||
return default_rules.get_next_action_candidates(ctx, limit=limit)
|
||||
|
||||
|
||||
default_strategy = DefaultNextActionStrategy()
|
||||
@@ -0,0 +1,74 @@
|
||||
"""Product/milestone-driven NextAction strategy — AP1.1."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from db import get_connection
|
||||
from psycopg2.extras import RealDictCursor
|
||||
from steering.signals import default_rules
|
||||
from steering.strategies.next_action.default_strategy import DefaultNextActionStrategy
|
||||
from tenant_context import TenantContext
|
||||
|
||||
_default = DefaultNextActionStrategy()
|
||||
|
||||
|
||||
class ProductMilestoneDrivenStrategy:
|
||||
key = "product_milestone_driven"
|
||||
|
||||
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)
|
||||
|
||||
candidates: list[dict[str, Any]] = []
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT
|
||||
'review_milestone' AS kind,
|
||||
m.title AS title,
|
||||
'Meilenstein prüfen oder Status aktualisieren' AS summary,
|
||||
m.initiative_id,
|
||||
NULL::uuid AS action_id,
|
||||
NULL::uuid AS backlog_item_id,
|
||||
'milestone_at_risk_or_active' AS reason_code,
|
||||
'Meilenstein prüfen' AS recommended_action
|
||||
FROM milestones m
|
||||
WHERE m.tenant_id = %s AND m.initiative_id = %s
|
||||
AND m.status IN ('at_risk', 'active')
|
||||
ORDER BY
|
||||
CASE m.status WHEN 'at_risk' THEN 0 ELSE 1 END,
|
||||
m.target_date ASC NULLS LAST,
|
||||
m.updated_at DESC
|
||||
LIMIT %s
|
||||
""",
|
||||
(ctx.tenant_id, initiative_id, limit),
|
||||
)
|
||||
for row in cur.fetchall():
|
||||
item = dict(row)
|
||||
item["initiative_id"] = str(item["initiative_id"])
|
||||
candidates.append(item)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
remaining = limit - len(candidates)
|
||||
if remaining > 0:
|
||||
rest = default_rules.get_next_action_candidates_for_initiative(
|
||||
ctx, initiative_id=initiative_id, limit=remaining
|
||||
)
|
||||
candidates.extend(rest)
|
||||
|
||||
return candidates[:limit]
|
||||
|
||||
|
||||
product_milestone_strategy = ProductMilestoneDrivenStrategy()
|
||||
@@ -0,0 +1,35 @@
|
||||
"""NextAction strategy registry — AP1.1."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Protocol
|
||||
|
||||
from tenant_context import TenantContext
|
||||
|
||||
_STRATEGIES: dict[str, "NextActionStrategy"] = {}
|
||||
|
||||
|
||||
class NextActionStrategy(Protocol):
|
||||
key: str
|
||||
|
||||
def evaluate(
|
||||
self,
|
||||
ctx: TenantContext,
|
||||
*,
|
||||
initiative_id: str | None = None,
|
||||
limit: int = 10,
|
||||
) -> list[dict[str, Any]]: ...
|
||||
|
||||
|
||||
def register_next_action_strategy(strategy: NextActionStrategy) -> None:
|
||||
if strategy.key in _STRATEGIES:
|
||||
raise ValueError(f"NextAction strategy already registered: {strategy.key}")
|
||||
_STRATEGIES[strategy.key] = strategy
|
||||
|
||||
|
||||
def get_next_action_strategy(key: str) -> NextActionStrategy | None:
|
||||
return _STRATEGIES.get(key)
|
||||
|
||||
|
||||
def clear_strategies_for_tests() -> None:
|
||||
_STRATEGIES.clear()
|
||||
Reference in new issue
Block a user