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

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:
LarsandCursor committed 2026-07-05 17:24:17 +02:00
1 parent 95feba6204
commit fc956d4ceb
27 files changed
+684 -15

No files matched your search

@@ -320,6 +320,7 @@ def get_initiative_steering_snapshot(
"lifecycle_state": steering["lifecycle_state"],
"lifecycle_label": steering["lifecycle_label"],
"method_key": steering["method_key"],
"method_label": steering.get("method_label"),
"method_version": steering["method_version"],
"operating_phase": phase,
"operating_phase_deprecated": True,
+2
View File
@@ -71,6 +71,7 @@ from routers import ( # noqa: E402
prompts,
recurring,
reviews,
steering,
workspace,
)
@@ -88,6 +89,7 @@ app.include_router(evidence.router)
app.include_router(decisions.router)
app.include_router(reviews.router)
app.include_router(recurring.router)
app.include_router(steering.router)
app.include_router(actors.router)
app.include_router(workspace.router)
+62
View File
@@ -0,0 +1,62 @@
"""Steering API — methods and context (AP1.1)."""
from __future__ import annotations
from typing import Literal, Optional
from capabilities import require_capability
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from services import initiatives as initiative_service
from services import steering_context as sc_service
from steering.context import get_steering_context_dto
from steering.methods.registry import list_methods
from tenant_context import TenantContext
router = APIRouter(prefix="/api/steering", tags=["steering"])
class SteeringContextUpdateRequest(BaseModel):
method_key: Optional[
Literal["generic_operating", "product_milestone_driven"]
] = None
@router.get("/methods")
def list_steering_methods(
ctx: TenantContext = Depends(require_capability("kairo.initiative.read")),
):
return [
{
"key": m.key,
"version": m.version,
"label": m.label,
"description": m.description,
"next_action_strategy_key": m.next_action_strategy_key,
}
for m in list_methods()
]
@router.patch("/initiatives/{initiative_id}/context")
def patch_initiative_steering_context(
initiative_id: str,
body: SteeringContextUpdateRequest,
ctx: TenantContext = Depends(require_capability("kairo.initiative.manage")),
):
if not initiative_service.get_initiative(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
):
raise HTTPException(status_code=404, detail="Vorhaben nicht gefunden")
if not body.method_key:
raise HTTPException(status_code=400, detail="method_key erforderlich")
try:
sc_service.update_method_key(
tenant_id=ctx.tenant_id,
initiative_id=initiative_id,
method_key=body.method_key,
user_id=ctx.user_id,
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
return get_steering_context_dto(ctx, initiative_id=initiative_id)
+51
View File
@@ -194,6 +194,57 @@ def update_lifecycle_state(
return result
def update_method_key(
*,
tenant_id: str,
initiative_id: str,
method_key: str,
user_id: Optional[str] = None,
) -> dict[str, Any]:
from steering.methods.registry import get_method
method = get_method(method_key)
if not method:
raise ValueError(f"Unbekannte Methode: {method_key}")
existing = get_steering_context(tenant_id=tenant_id, initiative_id=initiative_id)
if not existing:
raise ValueError("SteeringContext nicht gefunden")
conn = get_connection()
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(
"""
UPDATE steering_contexts
SET method_key = %s, method_version = %s, updated_at = NOW()
WHERE tenant_id = %s AND initiative_id = %s
RETURNING id, tenant_id, initiative_id, method_key, method_version,
lifecycle_state, lifecycle_metadata, created_at, updated_at
""",
(method.key, method.version, tenant_id, initiative_id),
)
row = cur.fetchone()
if not row:
raise ValueError("SteeringContext nicht gefunden")
result = _serialize_row(dict(row))
conn.commit()
finally:
conn.close()
log_audit(
"steering_context.method_changed",
user_id=user_id,
tenant_id=tenant_id,
details={
"initiative_id": initiative_id,
"from_method": existing["method_key"],
"to_method": method_key,
},
)
return result
def create_context_for_new_initiative(
*,
tenant_id: str,
+5 -2
View File
@@ -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()
+3
View File
@@ -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",
)
)
+3 -1
View File
@@ -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:
+24 -6
View File
@@ -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()
+62
View File
@@ -0,0 +1,62 @@
"""AP1.1 — Method Registry tests."""
from __future__ import annotations
from tests.factories import provision_user_in_tenant
from tests.test_initiatives_actions import (
_auth,
_create_initiative,
_login,
)
def test_list_steering_methods(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
res = client.get("/api/steering/methods", headers=_auth(token))
assert res.status_code == 200
methods = res.json()
keys = {m["key"] for m in methods}
assert "generic_operating" in keys
assert "product_milestone_driven" in keys
def test_change_initiative_method(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
initiative_id = _create_initiative(client, token).json()["id"]
res = client.patch(
f"/api/steering/initiatives/{initiative_id}/context",
json={"method_key": "product_milestone_driven"},
headers=_auth(token),
)
assert res.status_code == 200
assert res.json()["method_key"] == "product_milestone_driven"
assert res.json()["method_label"] == "Produkt / Meilenstein"
def test_product_milestone_next_action_prioritizes_milestone(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
initiative_id = _create_initiative(client, token).json()["id"]
client.patch(
f"/api/steering/initiatives/{initiative_id}/context",
json={"method_key": "product_milestone_driven"},
headers=_auth(token),
)
client.post(
f"/api/initiatives/{initiative_id}/milestones",
json={"title": "Release MVP", "status": "at_risk"},
headers=_auth(token),
)
snap = client.get(
f"/api/initiatives/{initiative_id}/steering-snapshot",
headers=_auth(token),
)
assert snap.status_code == 200
next_actions = snap.json()["next_actions"]
assert len(next_actions) >= 1
assert next_actions[0]["kind"] == "review_milestone"
+1 -1
View File
@@ -1,3 +1,3 @@
APP_VERSION = "0.11.0-ap1.0"
APP_VERSION = "0.11.1-ap1.1"
DB_SCHEMA_VERSION = "009"
APP_NAME = "jinkendo-kairo"