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
@@ -3,13 +3,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from steering.hooks.registry import register_builtin_hooks
|
||||
from steering.methods.registrations import generic_operating
|
||||
from steering.methods.registrations import generic_operating, product_milestone_driven
|
||||
from steering.strategies.next_action import register_builtin_strategies
|
||||
|
||||
|
||||
def bootstrap_steering() -> None:
|
||||
"""Register built-in hooks and methods (idempotent)."""
|
||||
"""Register built-in hooks, methods and strategies (idempotent)."""
|
||||
register_builtin_hooks()
|
||||
register_builtin_strategies()
|
||||
generic_operating.register()
|
||||
product_milestone_driven.register()
|
||||
|
||||
|
||||
bootstrap_steering()
|
||||
@@ -6,6 +6,7 @@ from typing import Any, Optional
|
||||
|
||||
from services import steering_context as sc_service
|
||||
from steering.lifecycle.states import lifecycle_label
|
||||
from steering.methods.registry import get_method
|
||||
from tenant_context import TenantContext
|
||||
|
||||
|
||||
@@ -20,9 +21,11 @@ def get_steering_context_dto(
|
||||
tenant_id=ctx.tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
)
|
||||
method = get_method(row["method_key"])
|
||||
return {
|
||||
**row,
|
||||
"lifecycle_label": lifecycle_label(row["lifecycle_state"]),
|
||||
"method_label": method.label if method else row["method_key"],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Built-in method: generic_operating — AP1.0."""
|
||||
"""Built-in method: generic_operating."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -13,7 +13,9 @@ def register() -> None:
|
||||
MethodDefinition(
|
||||
key="generic_operating",
|
||||
version="0.1.0",
|
||||
label="Allgemeine Steuerung",
|
||||
description="Standard-Lifecycle ohne methodenspezifische Spezialisierung",
|
||||
default_lifecycle_steps=STANDARD_LIFECYCLE_STEPS,
|
||||
next_action_strategy_key="default",
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
"""Built-in method: product_milestone_driven — AP1.1."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS
|
||||
from steering.methods.registry import MethodDefinition, get_method, register_method
|
||||
|
||||
_PRODUCT_STEPS = (
|
||||
"intake",
|
||||
"method_selection",
|
||||
"structure_setup",
|
||||
"planning",
|
||||
"action_selection",
|
||||
"assignment",
|
||||
"waiting",
|
||||
"result_intake",
|
||||
"validation",
|
||||
"review",
|
||||
"adaptation",
|
||||
"closure",
|
||||
)
|
||||
|
||||
|
||||
def register() -> None:
|
||||
if get_method("product_milestone_driven"):
|
||||
return
|
||||
register_method(
|
||||
MethodDefinition(
|
||||
key="product_milestone_driven",
|
||||
version="0.1.0",
|
||||
label="Produkt / Meilenstein",
|
||||
description="Meilenstein-orientierte Steuerung für Produkt- und Projektentwicklung",
|
||||
default_lifecycle_steps=_PRODUCT_STEPS,
|
||||
next_action_strategy_key="product_milestone_driven",
|
||||
)
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Method Registry — built-in steering methods (AP1.0)."""
|
||||
"""Method Registry — built-in steering methods."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -11,8 +11,10 @@ _METHODS: dict[str, "MethodDefinition"] = {}
|
||||
class MethodDefinition:
|
||||
key: str
|
||||
version: str
|
||||
label: str
|
||||
description: str
|
||||
default_lifecycle_steps: tuple[str, ...]
|
||||
next_action_strategy_key: str = "default"
|
||||
|
||||
|
||||
def register_method(defn: MethodDefinition) -> None:
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
"""Signal Engine — delegates to default rule provider (AP1.0)."""
|
||||
"""Signal Engine — method-aware NextAction (AP1.1)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
from services import steering_context as sc_service
|
||||
from steering.methods.registry import get_method
|
||||
from steering.signals import default_rules
|
||||
from steering.strategies.next_action.default_strategy import default_strategy
|
||||
from steering.strategies.next_action.registry import get_next_action_strategy
|
||||
from tenant_context import TenantContext
|
||||
|
||||
SignalKind = Literal["attention", "next_action"]
|
||||
|
||||
|
||||
def _resolve_method_key(ctx: TenantContext, initiative_id: str | None) -> str:
|
||||
if not initiative_id:
|
||||
return "generic_operating"
|
||||
row = sc_service.get_steering_context(
|
||||
tenant_id=ctx.tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if row:
|
||||
return row["method_key"]
|
||||
return "generic_operating"
|
||||
|
||||
|
||||
def evaluate(
|
||||
ctx: TenantContext,
|
||||
kind: SignalKind = "attention",
|
||||
@@ -19,8 +34,11 @@ def evaluate(
|
||||
) -> list[dict[str, Any]]:
|
||||
if kind == "attention":
|
||||
return default_rules.get_attention_items(ctx)
|
||||
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)
|
||||
|
||||
method_key = _resolve_method_key(ctx, initiative_id)
|
||||
method = get_method(method_key)
|
||||
strategy_key = (
|
||||
method.next_action_strategy_key if method else default_strategy.key
|
||||
)
|
||||
strategy = get_next_action_strategy(strategy_key) or default_strategy
|
||||
return strategy.evaluate(ctx, initiative_id=initiative_id, limit=limit)
|
||||
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