feat(steering): Kernel Spine v0.2 — Events, Slot-Provider, continuous_product
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 3m49s
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 19s
Test Suite / playwright-smoke (push) Successful in 12s
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 3m49s
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 19s
Test Suite / playwright-smoke (push) Successful in 12s
apply_steering_event an Action done, Gate verify/reopen und Blocker resolve; lifecycle-Ketten methodenaware via slot_map; continuous_product slot_map; pytest v0.2. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
606dd960b8
commit
fe1edb84f8
18 files changed
+595
-34
No files matched your search
@@ -1,7 +1,6 @@
|
||||
"""Steering Kernel Spine v0.1 — universal runtime entry for initiative steering."""
|
||||
"""Steering Kernel Spine — universal runtime entry for initiative steering."""
|
||||
|
||||
from steering.kernel.evaluate import evaluate_steering
|
||||
from steering.kernel.events import apply_steering_event
|
||||
from steering.kernel.models import HorizonMarker, LifecycleContext, SteeringBinding, SteeringEvaluation
|
||||
|
||||
__all__ = [
|
||||
@@ -9,6 +8,5 @@ __all__ = [
|
||||
"LifecycleContext",
|
||||
"SteeringBinding",
|
||||
"SteeringEvaluation",
|
||||
"apply_steering_event",
|
||||
"evaluate_steering",
|
||||
]
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Minimal TenantContext for service-layer steering calls."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from db import get_connection
|
||||
from psycopg2.extras import RealDictCursor
|
||||
from rights_registry import load_grants_for_roles
|
||||
from tenant_context import TenantContext
|
||||
|
||||
|
||||
def resolve_minimal_tenant_context(
|
||||
*,
|
||||
tenant_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> TenantContext:
|
||||
"""Build TenantContext for kernel calls from OM services (no HTTP session)."""
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"SELECT id, slug, name FROM tenants WHERE id = %s",
|
||||
(tenant_id,),
|
||||
)
|
||||
tenant = cur.fetchone()
|
||||
if not tenant:
|
||||
raise ValueError("Tenant nicht gefunden")
|
||||
|
||||
user_row = None
|
||||
membership_role: str | None = None
|
||||
actor_id: str | None = None
|
||||
if user_id:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT u.id, u.email, u.display_name, u.portal_role, tm.tenant_role
|
||||
FROM users u
|
||||
LEFT JOIN tenant_memberships tm
|
||||
ON tm.user_id = u.id AND tm.tenant_id = %s AND tm.is_active = TRUE
|
||||
WHERE u.id = %s
|
||||
""",
|
||||
(tenant_id, user_id),
|
||||
)
|
||||
user_row = cur.fetchone()
|
||||
if user_row:
|
||||
membership_role = user_row.get("tenant_role")
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id FROM actors
|
||||
WHERE tenant_id = %s AND user_id = %s AND actor_type = 'human'
|
||||
LIMIT 1
|
||||
""",
|
||||
(tenant_id, user_id),
|
||||
)
|
||||
actor = cur.fetchone()
|
||||
actor_id = str(actor["id"]) if actor else None
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
portal_role = user_row["portal_role"] if user_row else "user"
|
||||
caps = frozenset(
|
||||
load_grants_for_roles(
|
||||
portal_role=portal_role,
|
||||
tenant_role=membership_role,
|
||||
)
|
||||
)
|
||||
|
||||
return TenantContext(
|
||||
user_id=str(user_row["id"]) if user_row else "",
|
||||
email=user_row["email"] if user_row else "",
|
||||
display_name=user_row["display_name"] if user_row else "",
|
||||
portal_role=portal_role,
|
||||
tenant_id=str(tenant["id"]),
|
||||
tenant_slug=tenant["slug"],
|
||||
tenant_name=tenant["name"],
|
||||
tenant_role=membership_role,
|
||||
actor_id=actor_id,
|
||||
actor_type="human" if actor_id else None,
|
||||
session_token="steering-service",
|
||||
capabilities=caps,
|
||||
)
|
||||
@@ -1,17 +1,20 @@
|
||||
"""Event ingress stub — dual trigger (Plan | Event) v0.1."""
|
||||
"""Event ingress — dual trigger (Plan | Event) v0.2."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal
|
||||
from typing import Any
|
||||
|
||||
from steering.kernel.binding import resolve_primary_method_key
|
||||
from steering.kernel.evaluate import evaluate_steering
|
||||
from steering.lifecycle.event_transitions import EventKind
|
||||
from steering.lifecycle.orchestrator import transition
|
||||
from steering.lifecycle.slot_providers import (
|
||||
register_default_slot_providers,
|
||||
resolve_event_via_providers,
|
||||
)
|
||||
from tenant_context import TenantContext
|
||||
|
||||
EventKind = Literal[
|
||||
"actor_result",
|
||||
"external_event",
|
||||
"cadence_due",
|
||||
"situational",
|
||||
]
|
||||
register_default_slot_providers()
|
||||
|
||||
|
||||
def apply_steering_event(
|
||||
@@ -22,21 +25,48 @@ def apply_steering_event(
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Event-Schub in den Kernel (Stub v0.1).
|
||||
Event-Schub in den Kernel.
|
||||
|
||||
Plan-dominante Methoden: Event wird protokolliert, Auswertung erfolgt
|
||||
weiterhin über evaluate_steering (Plan-Zug). Volle Event-Pipeline folgt
|
||||
für dispute_procedure, care_navigation, recurring_control.
|
||||
Plan-dominante Methoden: Event aktualisiert lifecycle_state entlang slot_map,
|
||||
danach Re-Evaluate über evaluate_steering (Plan-Zug bleibt führend für Next).
|
||||
"""
|
||||
from steering.kernel.evaluate import evaluate_steering
|
||||
payload = payload or {}
|
||||
primary_key = resolve_primary_method_key(ctx, initiative_id)
|
||||
chain = resolve_event_via_providers(
|
||||
primary_method_key=primary_key,
|
||||
event_kind=event_kind,
|
||||
payload=payload,
|
||||
)
|
||||
|
||||
transitions: list[dict[str, Any]] = []
|
||||
handled = bool(chain)
|
||||
|
||||
for slot_state in chain:
|
||||
result = transition(
|
||||
ctx,
|
||||
initiative_id,
|
||||
slot_state,
|
||||
reason=f"steering_event:{event_kind}",
|
||||
tenant_id=ctx.tenant_id,
|
||||
user_id=ctx.user_id or None,
|
||||
)
|
||||
if not result.get("unchanged"):
|
||||
transitions.append(result)
|
||||
|
||||
evaluation = evaluate_steering(ctx, initiative_id=initiative_id)
|
||||
|
||||
return {
|
||||
"accepted": True,
|
||||
"event_kind": event_kind,
|
||||
"initiative_id": initiative_id,
|
||||
"handled": False,
|
||||
"message": "Event ingress stub — re-evaluate via Plan-Zug",
|
||||
"payload_keys": sorted((payload or {}).keys()),
|
||||
"handled": handled,
|
||||
"lifecycle_chain": list(chain),
|
||||
"transitions": transitions,
|
||||
"message": (
|
||||
"Lifecycle aktualisiert — Re-Evaluate via Plan-Zug"
|
||||
if handled
|
||||
else "Event protokolliert — kein Lifecycle-Slot für diese Methode"
|
||||
),
|
||||
"payload_keys": sorted(payload.keys()),
|
||||
"evaluation": evaluation.to_dict(),
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class SteeringEvaluation:
|
||||
lifecycle: LifecycleContext
|
||||
next_work: list[dict[str, Any]] = field(default_factory=list)
|
||||
attention: list[dict[str, Any]] = field(default_factory=list)
|
||||
data_source: str = "steering_kernel_v0.1.1"
|
||||
data_source: str = "steering_kernel_v0.2"
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user