feat(steering): Kernel Spine v0.1.1 als zentraler Initiative-Einstieg
Deploy Development / deploy (push) Successful in 48s
Test Suite / pytest-backend (push) Failing after 3m33s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped

evaluate_steering() vereinheitlicht Horizon, Next Work und Attention; Snapshot und Signal Engine delegieren dorthin; slot_map deklarativ fuer sequential_dependency und generic_operating.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-26 16:08:58 +02:00
1 parent 753f178b0c
commit 75a6a63665
20 files changed
+923 -51

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
"""Steering Kernel Spine v0.1 — 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__ = [
"HorizonMarker",
"LifecycleContext",
"SteeringBinding",
"SteeringEvaluation",
"apply_steering_event",
"evaluate_steering",
]
+162
View File
@@ -0,0 +1,162 @@
"""Attention evaluation (Q5) — method- and horizon-aware for one initiative."""
from __future__ import annotations
from typing import Any
from steering.kernel.models import HorizonMarker, SteeringBinding
from steering.strategies.next_action.execution_ready import gate_horizon_scope_for_method
from tenant_context import TenantContext
_GATE_METHODS = frozenset(
{
"sequential_dependency",
"program_delivery",
"maturity_progression",
}
)
def evaluate_attention(
ctx: TenantContext,
*,
initiative_id: str,
binding: SteeringBinding,
horizon: HorizonMarker,
next_work: list[dict[str, Any]],
limit: int = 20,
) -> list[dict[str, Any]]:
"""Kernel attention for a single initiative — no fake next when planning debt."""
from services import actions as action_service
from services import blockers as blocker_service
from services import roadmap as roadmap_service
from services.execution_plan import list_dependencies_for_initiative
from steering.graph.execution_engine import (
compute_execution_graph_state,
compute_planning_debt,
execution_waiting_to_attention_items,
planning_debt_to_attention_items,
)
items: list[dict[str, Any]] = []
blockers = blocker_service.list_blockers_for_initiative(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
for blocker in blockers:
if blocker.get("status") not in ("open", "in_progress"):
continue
items.append(
{
"kind": "open_blocker",
"severity": "warning",
"title": blocker.get("title") or "Blocker",
"summary": "Offener Blocker im Vorhaben",
"scope_type": "blocker",
"scope_id": str(blocker["id"]),
"initiative_id": initiative_id,
"action_id": (
str(blocker["action_id"]) if blocker.get("action_id") else None
),
"blocker_id": str(blocker["id"]),
"reason_code": "path_blocked",
"data_source": "steering_kernel",
}
)
actions = action_service.list_actions_for_initiative(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
for action in actions:
if action.get("status") != "blocked":
continue
items.append(
{
"kind": "blocked_action",
"severity": "critical",
"title": action.get("title") or "Arbeitspaket",
"summary": "Maßnahme ist blockiert",
"scope_type": "action",
"scope_id": str(action["id"]),
"initiative_id": initiative_id,
"action_id": str(action["id"]),
"reason_code": "path_blocked",
"data_source": "steering_kernel",
}
)
gate_scope = gate_horizon_scope_for_method(
binding.primary_method_key, ctx, initiative_id
)
roadmap_items = roadmap_service.list_roadmap_items_for_initiative(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
scoped_roadmap = roadmap_items
scoped_actions = actions
if gate_scope:
scope = str(gate_scope)
scoped_roadmap = [ri for ri in roadmap_items if str(ri.get("id")) == scope]
scoped_actions = [
a
for a in actions
if a.get("roadmap_item_id") and str(a["roadmap_item_id"]) == scope
]
if binding.primary_method_key in _GATE_METHODS:
debts = compute_planning_debt(
actions=scoped_actions, roadmap_items=scoped_roadmap
)
items.extend(
planning_debt_to_attention_items(
initiative_id=initiative_id, debts=debts
)
)
dependencies = list_dependencies_for_initiative(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
graph_state = compute_execution_graph_state(
actions=actions,
dependencies=dependencies,
scope_roadmap_item_id=gate_scope,
)
items.extend(
execution_waiting_to_attention_items(
initiative_id=initiative_id,
actions=actions,
graph_state=graph_state,
)
)
if (
not next_work
and binding.primary_method_key in _GATE_METHODS
and horizon.kind == "gate"
):
has_planning = any(i.get("reason_code") == "planning_debt" for i in items)
has_waiting = any(i.get("reason_code") == "execution_waiting" for i in items)
if not has_planning and not has_waiting and not graph_state.get("ready_actions"):
items.append(
{
"kind": "initiative_without_next_action",
"severity": "info",
"title": horizon.gate_title or "Aktiver Horizont",
"summary": "Keine ausführungsbereite Arbeit im aktiven Horizont",
"scope_type": "milestone",
"scope_id": horizon.gate_roadmap_item_id,
"initiative_id": initiative_id,
"reason_code": "horizon_no_ready_work",
"data_source": "steering_kernel",
}
)
for item in items:
item.setdefault("data_source", "steering_kernel")
items.sort(
key=lambda x: {"critical": 0, "warning": 1, "info": 2}.get(
x.get("severity", "info"), 9
)
)
return items[:limit]
+52
View File
@@ -0,0 +1,52 @@
"""Resolve primary method and composition modifier."""
from __future__ import annotations
from services import steering_context as sc_service
from services.work_cycle import get_active_work_cycle
from steering.kernel.models import SteeringBinding
from steering.methods.registry import get_method
from steering.strategies.next_action.default_strategy import default_strategy
from tenant_context import TenantContext
_AGILE_KEY = "agile_iteration"
def resolve_primary_method_key(ctx: TenantContext, initiative_id: str) -> str:
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 _primary_composes_with_agile(primary_method_key: str) -> bool:
agile = get_method(_AGILE_KEY)
if not agile:
return False
return primary_method_key in agile.composes_with
def resolve_steering_binding(ctx: TenantContext, initiative_id: str) -> SteeringBinding:
primary_key = resolve_primary_method_key(ctx, initiative_id)
primary = get_method(primary_key)
primary_strategy = (
primary.next_action_strategy_key if primary else default_strategy.key
)
composition: str | None = None
strategy_key = primary_strategy
active_cycle = get_active_work_cycle(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
if active_cycle and _primary_composes_with_agile(primary_key):
composition = _AGILE_KEY
strategy_key = _AGILE_KEY
return SteeringBinding(
primary_method_key=primary_key,
composition_modifier=composition,
next_work_strategy_key=strategy_key,
)
+66
View File
@@ -0,0 +1,66 @@
"""Steering Kernel Spine — single entry point v0.1."""
from __future__ import annotations
from steering.kernel.attention import evaluate_attention
from steering.kernel.binding import resolve_steering_binding
from steering.kernel.horizon import resolve_horizon
from steering.kernel.lifecycle import resolve_lifecycle_context
from steering.kernel.models import SteeringEvaluation
from steering.kernel.next_work import evaluate_next_work
from tenant_context import TenantContext
def evaluate_steering(
ctx: TenantContext,
*,
initiative_id: str,
next_work_limit: int = 10,
attention_limit: int = 20,
) -> SteeringEvaluation:
"""
Herzmaschine — ein Wahrheitsmodell pro Vorhaben.
Alle Initiative-Steuerung (Snapshot, Cockpit, API) muss hier durch.
"""
if next_work_limit < 1:
next_work_limit = 1
if attention_limit < 1:
attention_limit = 1
binding = resolve_steering_binding(ctx, initiative_id)
lifecycle = resolve_lifecycle_context(
ctx, initiative_id=initiative_id, binding=binding
)
horizon = resolve_horizon(
ctx,
initiative_id=initiative_id,
primary_method_key=binding.primary_method_key,
composition_modifier=binding.composition_modifier,
)
next_work = evaluate_next_work(
ctx,
initiative_id=initiative_id,
binding=binding,
horizon=horizon,
limit=next_work_limit,
)
attention = evaluate_attention(
ctx,
initiative_id=initiative_id,
binding=binding,
horizon=horizon,
next_work=next_work,
limit=attention_limit,
)
return SteeringEvaluation(
initiative_id=initiative_id,
binding=binding,
horizon=horizon,
lifecycle=lifecycle,
next_work=next_work,
attention=attention,
)
+42
View File
@@ -0,0 +1,42 @@
"""Event ingress stub — dual trigger (Plan | Event) v0.1."""
from __future__ import annotations
from typing import Any, Literal
from tenant_context import TenantContext
EventKind = Literal[
"actor_result",
"external_event",
"cadence_due",
"situational",
]
def apply_steering_event(
ctx: TenantContext,
*,
initiative_id: str,
event_kind: EventKind,
payload: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""
Event-Schub in den Kernel (Stub v0.1).
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.
"""
from steering.kernel.evaluate import evaluate_steering
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()),
"evaluation": evaluation.to_dict(),
}
+67
View File
@@ -0,0 +1,67 @@
"""Horizon resolution (Q1)."""
from __future__ import annotations
from steering.kernel.models import HorizonMarker
from steering.strategies.next_action.execution_ready import (
first_active_gate_id,
gate_horizon_scope_for_method,
)
from services.work_cycle import get_active_work_cycle
from tenant_context import TenantContext
def resolve_horizon(
ctx: TenantContext,
*,
initiative_id: str,
primary_method_key: str,
composition_modifier: str | None,
) -> HorizonMarker:
gate_id = gate_horizon_scope_for_method(
primary_method_key, ctx, initiative_id
)
gate_title: str | None = None
if gate_id:
gate_title = _load_gate_title(ctx, gate_id)
active_cycle = get_active_work_cycle(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
if composition_modifier and active_cycle:
return HorizonMarker(
kind="work_cycle",
gate_roadmap_item_id=gate_id,
gate_title=gate_title,
work_cycle_id=str(active_cycle["id"]),
work_cycle_title=active_cycle.get("title"),
)
if gate_id:
return HorizonMarker(
kind="gate",
gate_roadmap_item_id=gate_id,
gate_title=gate_title,
)
return HorizonMarker(kind="none")
def _load_gate_title(ctx: TenantContext, gate_id: str) -> str | None:
from db import get_connection
from psycopg2.extras import RealDictCursor
conn = get_connection()
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(
"""
SELECT title FROM roadmap_items
WHERE id = %s AND tenant_id = %s
""",
(gate_id, ctx.tenant_id),
)
row = cur.fetchone()
return row["title"] if row else None
finally:
conn.close()
+65
View File
@@ -0,0 +1,65 @@
"""Lifecycle slot resolution — Kernel §4 (declarative, v0.1.1)."""
from __future__ import annotations
from typing import Any
from steering.kernel.models import LifecycleContext, SteeringBinding
from steering.lifecycle.slot_maps import (
active_slot_keys,
is_slot_operational,
slot_map_from_tuple,
)
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS, lifecycle_label
from steering.methods.registry import get_method
from services import steering_context as sc_service
from tenant_context import TenantContext
def _derive_slot_map_from_steps(steps: tuple[str, ...]) -> dict[str, str]:
active = set(steps)
return {
step: ("active" if step in active else "n/a") for step in STANDARD_LIFECYCLE_STEPS
}
def resolve_method_slot_map(method_key: str) -> dict[str, str]:
method = get_method(method_key)
if not method:
return _derive_slot_map_from_steps(STANDARD_LIFECYCLE_STEPS)
if method.slot_map:
return slot_map_from_tuple(method.slot_map)
return _derive_slot_map_from_steps(method.default_lifecycle_steps)
def resolve_lifecycle_context(
ctx: TenantContext,
*,
initiative_id: str,
binding: SteeringBinding,
) -> LifecycleContext:
slot_map = resolve_method_slot_map(binding.primary_method_key)
row = sc_service.get_steering_context(
tenant_id=ctx.tenant_id, initiative_id=initiative_id
)
current_state = row["lifecycle_state"] if row else "intake"
if current_state not in STANDARD_LIFECYCLE_STEPS:
current_state = "intake"
active = active_slot_keys(slot_map) # type: ignore[arg-type]
operational = tuple(
step for step in STANDARD_LIFECYCLE_STEPS if is_slot_operational(slot_map.get(step, "n/a")) # type: ignore[arg-type]
)
return LifecycleContext(
current_state=current_state,
current_state_label=lifecycle_label(current_state),
slot_map=slot_map,
active_slots=active,
operational_slots=operational,
)
def lifecycle_to_dict(lifecycle: LifecycleContext) -> dict[str, Any]:
return lifecycle.to_dict()
+81
View File
@@ -0,0 +1,81 @@
"""Steering Kernel Spine — data models v0.1.1."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Literal
@dataclass(frozen=True)
class HorizonMarker:
"""Aktiver Steuerungs-Horizont (Q1)."""
kind: Literal["gate", "work_cycle", "none"]
gate_roadmap_item_id: str | None = None
gate_title: str | None = None
work_cycle_id: str | None = None
work_cycle_title: str | None = None
def to_dict(self) -> dict[str, Any]:
return {
"kind": self.kind,
"gate_roadmap_item_id": self.gate_roadmap_item_id,
"gate_title": self.gate_title,
"work_cycle_id": self.work_cycle_id,
"work_cycle_title": self.work_cycle_title,
}
@dataclass(frozen=True)
class SteeringBinding:
"""Aufgelöste Methode: Primary + optional Composition."""
primary_method_key: str
composition_modifier: str | None
next_work_strategy_key: str
@dataclass(frozen=True)
class LifecycleContext:
"""Deklarativer Lifecycle-Vertrag + persistierter Pointer."""
current_state: str
current_state_label: str
slot_map: dict[str, str]
active_slots: tuple[str, ...]
operational_slots: tuple[str, ...]
def to_dict(self) -> dict[str, Any]:
return {
"current_state": self.current_state,
"current_state_label": self.current_state_label,
"slot_map": dict(self.slot_map),
"active_slots": list(self.active_slots),
"operational_slots": list(self.operational_slots),
}
@dataclass
class SteeringEvaluation:
"""Ergebnis von evaluate_steering — ein Wahrheitsmodell pro Vorhaben."""
initiative_id: str
binding: SteeringBinding
horizon: HorizonMarker
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"
def to_dict(self) -> dict[str, Any]:
return {
"initiative_id": self.initiative_id,
"primary_method_key": self.binding.primary_method_key,
"composition_modifier": self.binding.composition_modifier,
"next_work_strategy_key": self.binding.next_work_strategy_key,
"horizon": self.horizon.to_dict(),
"lifecycle": self.lifecycle.to_dict(),
"next_work": self.next_work,
"attention": self.attention,
"data_source": self.data_source,
}
+37
View File
@@ -0,0 +1,37 @@
"""Next work evaluation (Schlitz 5) — routes to registered strategies only."""
from __future__ import annotations
from typing import Any
from steering.kernel.models import HorizonMarker, SteeringBinding
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
def evaluate_next_work(
ctx: TenantContext,
*,
initiative_id: str,
binding: SteeringBinding,
horizon: HorizonMarker,
limit: int,
) -> list[dict[str, Any]]:
"""Invoke the bound next-work strategy (primary or composition)."""
if limit < 1:
limit = 1
strategy = get_next_action_strategy(binding.next_work_strategy_key) or default_strategy
candidates = strategy.evaluate(
ctx, initiative_id=initiative_id, limit=limit
)
for item in candidates:
item.setdefault("data_source", "steering_kernel")
if horizon.gate_roadmap_item_id:
item.setdefault("horizon_gate_id", horizon.gate_roadmap_item_id)
if horizon.work_cycle_id:
item.setdefault("horizon_work_cycle_id", horizon.work_cycle_id)
return candidates[:limit]