AP2.0: Archetyp-Katalog, Method-Stubs und sichtbare Steuerung in Kontrolle.
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Failing after 2m2s
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 3s
Test Suite / compose-smoke (push) Has been skipped

PO-Dokumente (ADP v0.2, MVP v0.3) und Minimal Complete Slice: Registry-Methoden, Initiative/Project-Spiegel, Default-Methode bei Anlage, Lagebild mit Archetyp und Guidance.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-10 10:44:38 +02:00
1 parent 21d948634e
commit 3bd983297b
30 files changed
+2093 -52

No files matched your search

+52
View File
@@ -11,6 +11,7 @@ from psycopg2.extras import RealDictCursor
from db import get_connection
from data_layer.attention import get_next_action_candidates_for_initiative
from entity_archetypes.registry import archetype_label
from steering.context import get_steering_context_dto
from steering.signals.snapshot_signals import derive_initiative_signals
from services.initiatives import get_initiative
@@ -20,6 +21,41 @@ OPEN_BLOCKER = ("open", "in_progress")
OPEN_ACTION = ("open", "ready", "in_progress", "blocked", "review_required")
ACTIVE_INITIATIVE = ("active", "paused")
_REASON_LABELS = {
"open_action_priority": "Offenes Arbeitspaket",
"milestone_at_risk_or_active": "Plan-Element aktiv oder gefährdet",
"blocked_action": "Blockiertes Arbeitspaket",
"backlog_triage": "Eingang triagieren",
}
def _steering_guidance(
*,
next_actions: list[dict[str, Any]],
signals: list[str],
method_key: str,
) -> str:
if next_actions:
item = next_actions[0]
title = item.get("title") or "Nächster Schritt"
hint = (
item.get("recommended_action")
or item.get("summary")
or _REASON_LABELS.get(item.get("reason_code", ""), "")
)
if hint:
return f"Als Nächstes: {title} — {hint}"
return f"Als Nächstes: {title}"
if signals:
return "Attention: Struktur oder Ist-Arbeit ergänzen, um Next Actions zu erzeugen."
return (
f"Methode {method_key}: Plan oder Eingang befüllen, dann committete Arbeit starten."
)
def _attention_items(signals: list[str]) -> list[dict[str, str]]:
return [{"code": code, "label": code.replace("_", " ")} for code in signals]
def _sid(value: Any) -> Optional[str]:
return str(value) if value else None
@@ -261,16 +297,32 @@ def get_initiative_steering_snapshot(
)
steering = get_steering_context_dto(ctx, initiative_id=initiative_id)
metadata = steering.get("lifecycle_metadata") or {}
if isinstance(metadata, str):
metadata = {}
method_profile_key = metadata.get("method_profile_key")
initiative_archetype = initiative.get("archetype_key") or "initiative.generic"
return {
"initiative_id": initiative_id,
"initiative_title": initiative["title"],
"initiative_status": initiative["status"],
"archetype_key": initiative_archetype,
"archetype_label": archetype_label(
entity_type="initiative", archetype_key=initiative_archetype
),
"method_profile_key": method_profile_key,
"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"],
"steering_guidance": _steering_guidance(
next_actions=next_actions,
signals=signals,
method_key=steering["method_key"],
),
"attention_items": _attention_items(signals),
"signals": signals,
"upcoming_milestones": upcoming_milestones,
"upcoming_roadmap_items": upcoming_milestones,
+8
View File
@@ -1,13 +1,21 @@
from entity_archetypes.registry import (
ENTITY_ARCHETYPES,
INITIATIVE_ARCHETYPES,
PROJECT_ARCHETYPES,
archetype_label,
list_archetypes,
mirror_project_archetype_key,
resolve_default_method_key,
validate_archetype_key,
)
__all__ = [
"ENTITY_ARCHETYPES",
"INITIATIVE_ARCHETYPES",
"PROJECT_ARCHETYPES",
"archetype_label",
"list_archetypes",
"mirror_project_archetype_key",
"resolve_default_method_key",
"validate_archetype_key",
]
+142 -29
View File
@@ -1,4 +1,4 @@
"""System-Archetypen (AP1.10a/10b) — In-Memory-Seed + DB-Registry."""
"""System-Archetypen (AP1.10 + AP2.0) — Seeds, Bindings, Spiegel Project."""
from __future__ import annotations
@@ -8,39 +8,136 @@ from psycopg2.extras import RealDictCursor
from db import get_connection
INITIATIVE_ARCHETYPES: tuple[dict[str, Any], ...] = (
{
"key": "initiative.generic",
"entity_type": "initiative",
"label": "Allgemeines Vorhaben",
"description": "Standard-Vorhaben ohne spezielle Vorlage.",
"is_system": True,
},
{
"key": "initiative.program",
"entity_type": "initiative",
"label": "Programm / Mega-Vorhaben",
"description": "Mehrere Stränge, Zielzustand und Vision zentral.",
"is_system": True,
},
{
"key": "initiative.product",
"entity_type": "initiative",
"label": "Produkt / Release",
"description": "Produkt- oder Release-orientiertes Vorhaben.",
"is_system": True,
},
# initiative suffix → default method (shared by initiative + project mirror)
_METHOD_BY_SUFFIX: dict[str, str] = {
"generic": "generic_operating",
"maturity_journey": "maturity_progression",
"linear_project": "sequential_dependency",
"recurring_program": "recurring_control",
"support_queue": "queue_pull",
"program": "program_delivery",
"product": "continuous_product",
"dispute_case": "dispute_procedure",
"content_project": "chapter_based_progression",
}
_INITIATIVE_SPEC_META: tuple[tuple[str, str, str], ...] = (
("generic", "Allgemeines Vorhaben", "Fallback ohne spezielle Steuerungsvorlage."),
(
"maturity_journey",
"Reifegrad-Entwicklung",
"Mehrstufige Entwicklung, Routinen, Graph-Voraussetzungen.",
),
(
"linear_project",
"Lineares Vorhaben",
"Einmalprojekte mit Pfaden, Gates und Graph.",
),
(
"recurring_program",
"Dauerprogramm / Rhythmus",
"Haushalt, Rhythmen, Abweichungs-Steuerung.",
),
(
"support_queue",
"Inbox / Queue",
"Ad-hoc-Eingang, triage, thematische Zuordnung.",
),
(
"program",
"Programm (begrenzt)",
"Phasen, Release-Programm mit Abschluss.",
),
(
"product",
"Produkt (kontinuierlich)",
"Dauerbetrieb, Wartung, Issues, Weiterentwicklung.",
),
(
"dispute_case",
"Verfahren / Konflikt",
"Reaktive Steuerung, Fristen, Entscheidungen.",
),
(
"content_project",
"Inhalt / Kapitel",
"Bücher, Konzepte, Kapitelstruktur.",
),
)
_ARCHETYPE_INDEX = {
(item["entity_type"], item["key"]): item for item in INITIATIVE_ARCHETYPES
def _build_specs() -> tuple[dict[str, Any], ...]:
specs: list[dict[str, Any]] = []
for suffix, label, description in _INITIATIVE_SPEC_META:
method = _METHOD_BY_SUFFIX[suffix]
specs.append(
{
"key": f"initiative.{suffix}",
"entity_type": "initiative",
"label": label,
"description": description,
"is_system": True,
"default_method_key": method,
"default_method_profile_key": None,
}
)
specs.append(
{
"key": f"project.{suffix}",
"entity_type": "project",
"label": label,
"description": f"Project-Spiegel: {description}",
"is_system": True,
"default_method_key": method,
"default_method_profile_key": None,
}
)
return tuple(specs)
ENTITY_ARCHETYPES: tuple[dict[str, Any], ...] = _build_specs()
INITIATIVE_ARCHETYPES: tuple[dict[str, Any], ...] = tuple(
item for item in ENTITY_ARCHETYPES if item["entity_type"] == "initiative"
)
PROJECT_ARCHETYPES: tuple[dict[str, Any], ...] = tuple(
item for item in ENTITY_ARCHETYPES if item["entity_type"] == "project"
)
_ARCHETYPE_INDEX: dict[tuple[str, str], dict[str, Any]] = {
(item["entity_type"], item["key"]): item for item in ENTITY_ARCHETYPES
}
_KEY_INDEX: dict[str, dict[str, Any]] = {item["key"]: item for item in ENTITY_ARCHETYPES}
def _list_archetypes_from_memory(*, entity_type: Optional[str] = None) -> list[dict[str, Any]]:
if entity_type is None:
return [dict(item) for item in INITIATIVE_ARCHETYPES]
return [dict(item) for item in INITIATIVE_ARCHETYPES if item["entity_type"] == entity_type]
items = ENTITY_ARCHETYPES
if entity_type is not None:
items = tuple(i for i in items if i["entity_type"] == entity_type)
return [_public_archetype(item) for item in items]
def _public_archetype(item: dict[str, Any]) -> dict[str, Any]:
return {
"key": item["key"],
"entity_type": item["entity_type"],
"label": item["label"],
"description": item["description"],
"is_system": item["is_system"],
"default_method_key": item["default_method_key"],
"default_method_profile_key": item.get("default_method_profile_key"),
}
def _enrich_row(row: dict[str, Any]) -> dict[str, Any]:
base = dict(row)
spec = _KEY_INDEX.get(base.get("key", ""))
if spec:
base.setdefault("default_method_key", spec["default_method_key"])
base.setdefault("default_method_profile_key", spec.get("default_method_profile_key"))
return base
def list_archetypes(*, entity_type: Optional[str] = None) -> list[dict[str, Any]]:
@@ -67,7 +164,7 @@ def list_archetypes(*, entity_type: Optional[str] = None) -> list[dict[str, Any]
)
rows = cur.fetchall()
if rows:
return [dict(row) for row in rows]
return [_enrich_row(dict(row)) for row in rows]
except Exception:
pass
finally:
@@ -83,3 +180,19 @@ def validate_archetype_key(*, entity_type: str, archetype_key: str) -> None:
def archetype_label(*, entity_type: str, archetype_key: str) -> Optional[str]:
item = _ARCHETYPE_INDEX.get((entity_type, archetype_key))
return item["label"] if item else None
def resolve_default_method_key(archetype_key: str) -> str:
spec = _KEY_INDEX.get(archetype_key)
if not spec:
return "generic_operating"
return spec.get("default_method_key", "generic_operating")
def mirror_project_archetype_key(initiative_archetype_key: str) -> str:
if initiative_archetype_key.startswith("initiative."):
suffix = initiative_archetype_key[len("initiative.") :]
candidate = f"project.{suffix}"
if ( "project", candidate) in _ARCHETYPE_INDEX:
return candidate
return "project.generic"
+41 -1
View File
@@ -1,4 +1,4 @@
"""System-Felddefinitionen (Seed) — AP1.10b."""
"""System-Felddefinitionen (Seed) — AP1.10b / AP2.0b."""
from __future__ import annotations
@@ -45,4 +45,44 @@ FIELD_DEFINITIONS: tuple[dict[str, Any], ...] = (
"sort_order": 20,
"validation_json": {},
},
{
"archetype_key": "initiative.maturity_journey",
"field_key": "current_focus",
"field_type": "text",
"label": "Aktueller Fokus",
"required": False,
"searchable": True,
"sort_order": 10,
"validation_json": {},
},
{
"archetype_key": "initiative.maturity_journey",
"field_key": "training_frequency",
"field_type": "enum",
"label": "Trainingsfrequenz",
"required": False,
"searchable": False,
"sort_order": 20,
"validation_json": {"options": ["daily", "3x_week", "weekly", "flexible"]},
},
{
"archetype_key": "initiative.content_project",
"field_key": "manuscript_status",
"field_type": "text",
"label": "Manuskript-Status",
"required": False,
"searchable": True,
"sort_order": 10,
"validation_json": {},
},
{
"archetype_key": "initiative.content_project",
"field_key": "word_count_goal",
"field_type": "number",
"label": "Wortziel",
"required": False,
"searchable": False,
"sort_order": 20,
"validation_json": {},
},
)
+4 -4
View File
@@ -1,11 +1,11 @@
"""Sync Entity-Archetypen und Felddefinitionen in PostgreSQL — AP1.10b."""
"""Sync Entity-Archetypen und Felddefinitionen in PostgreSQL — AP1.10b / AP2.0b."""
from __future__ import annotations
import json
from db import get_connection
from entity_archetypes.registry import INITIATIVE_ARCHETYPES
from entity_archetypes.registry import ENTITY_ARCHETYPES
from entity_fields.definitions import FIELD_DEFINITIONS
@@ -13,7 +13,7 @@ def sync_entity_field_registry_to_db() -> int:
conn = get_connection()
try:
with conn.cursor() as cur:
for archetype in INITIATIVE_ARCHETYPES:
for archetype in ENTITY_ARCHETYPES:
cur.execute(
"""
INSERT INTO entity_archetypes (
@@ -68,7 +68,7 @@ def sync_entity_field_registry_to_db() -> int:
conn.commit()
print(
"[entity_fields] Sync OK — "
f"{len(INITIATIVE_ARCHETYPES)} Archetyp(en), "
f"{len(ENTITY_ARCHETYPES)} Archetyp(en), "
f"{len(FIELD_DEFINITIONS)} Felddefinition(en)"
)
return 0
+1
View File
@@ -0,0 +1 @@
"""Package marker for method profile seeds."""
+63
View File
@@ -0,0 +1,63 @@
"""Referenz-Ausprägungen (Method Profiles) — Code-Seeds AP2.0b."""
from __future__ import annotations
from typing import Any, Optional
METHOD_PROFILES: tuple[dict[str, Any], ...] = (
{
"key": "maturity.karate_kumite",
"label": "Karate Kumite",
"description": "Mehrere Fähigkeiten mit Stufen, Routinen und Voraussetzungs-Graph.",
"initiative_archetype_key": "initiative.maturity_journey",
"method_key": "maturity_progression",
"seed_hints": {
"skill_count": 8,
"stages_per_skill": "5-7",
"graph_prerequisites": True,
},
},
{
"key": "content.book_writing",
"label": "Buch schreiben",
"description": "Kapitelstruktur, Schreib-APs, Review-Gates.",
"initiative_archetype_key": "initiative.content_project",
"method_key": "chapter_based_progression",
"seed_hints": {
"roadmap_item_type": "chapter",
"review_gates": True,
},
},
{
"key": "product.kairo_dev",
"label": "Kairo Entwicklung",
"description": "Kontinuierliches Produkt mit Gate-Orientierung und optionaler Sprint-Zeitbox.",
"initiative_archetype_key": "initiative.product",
"method_key": "continuous_product",
"seed_hints": {
"agile_iteration_profile": True,
"default_actor_setup": "po_plus_vibe_coder",
},
},
)
_PROFILE_INDEX = {item["key"]: item for item in METHOD_PROFILES}
def get_method_profile(key: str) -> Optional[dict[str, Any]]:
item = _PROFILE_INDEX.get(key)
return dict(item) if item else None
def list_method_profiles(*, initiative_archetype_key: Optional[str] = None) -> list[dict[str, Any]]:
items = METHOD_PROFILES
if initiative_archetype_key:
items = tuple(
i for i in items if i["initiative_archetype_key"] == initiative_archetype_key
)
return [dict(item) for item in items]
def resolve_method_for_profile(profile_key: str) -> Optional[str]:
profile = get_method_profile(profile_key)
return profile["method_key"] if profile else None
@@ -0,0 +1,27 @@
-- AP2.0b: Project archetype_key (Spiegel der Initiative)
ALTER TABLE projects
ADD COLUMN IF NOT EXISTS archetype_key VARCHAR(64) NULL;
CREATE INDEX IF NOT EXISTS idx_projects_archetype
ON projects (tenant_id, archetype_key)
WHERE archetype_key IS NOT NULL;
-- Bestehende Projects: Mirror aus Initiative (einmalig)
UPDATE projects p
SET archetype_key = CASE i.archetype_key
WHEN 'initiative.generic' THEN 'project.generic'
WHEN 'initiative.maturity_journey' THEN 'project.maturity_journey'
WHEN 'initiative.linear_project' THEN 'project.linear_project'
WHEN 'initiative.recurring_program' THEN 'project.recurring_program'
WHEN 'initiative.support_queue' THEN 'project.support_queue'
WHEN 'initiative.program' THEN 'project.program'
WHEN 'initiative.product' THEN 'project.product'
WHEN 'initiative.dispute_case' THEN 'project.dispute_case'
WHEN 'initiative.content_project' THEN 'project.content_project'
ELSE 'project.generic'
END
FROM initiatives i
WHERE p.initiative_id = i.id
AND p.tenant_id = i.tenant_id
AND p.archetype_key IS NULL;
+1
View File
@@ -124,6 +124,7 @@ def create_initiative(
tenant_id=tenant_id,
initiative_id=row["id"],
user_id=user_id,
archetype_key=archetype_key,
)
return row
+13 -4
View File
@@ -9,6 +9,7 @@ from psycopg2.extras import RealDictCursor
from db import get_connection
from services.audit import log_audit
from entity_archetypes import mirror_project_archetype_key, validate_archetype_key
from services.initiatives import get_initiative
ProjectStatus = Literal["active", "paused", "completed", "archived"]
@@ -21,7 +22,7 @@ MAX_PROJECT_DEPTH = 5
_PROJECT_COLUMNS = """
id, tenant_id, initiative_id, parent_project_id, container_kind,
title, description, status,
archetype_key, title, description, status,
roadmap_item_id, sort_order, target_date, created_at, updated_at
"""
@@ -227,6 +228,7 @@ def create_project(
roadmap_item_id: Optional[str] = None,
sort_order: int = 0,
target_date: Optional[date] = None,
archetype_key: Optional[str] = None,
user_id: Optional[str] = None,
) -> dict[str, Any]:
title = title.strip()
@@ -234,9 +236,15 @@ def create_project(
raise ValueError("Titel ist erforderlich")
_validate_status(status)
_validate_container_kind(container_kind)
if not get_initiative(tenant_id=tenant_id, initiative_id=initiative_id):
initiative = get_initiative(tenant_id=tenant_id, initiative_id=initiative_id)
if not initiative:
raise ValueError("Initiative nicht gefunden")
resolved_archetype = archetype_key or mirror_project_archetype_key(
initiative["archetype_key"]
)
validate_archetype_key(entity_type="project", archetype_key=resolved_archetype)
conn = get_connection()
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
@@ -257,10 +265,10 @@ def create_project(
f"""
INSERT INTO projects (
tenant_id, initiative_id, parent_project_id, container_kind,
title, description, status,
archetype_key, title, description, status,
roadmap_item_id, sort_order, target_date
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
RETURNING {_PROJECT_COLUMNS}
""",
(
@@ -268,6 +276,7 @@ def create_project(
initiative_id,
parent_project_id,
container_kind,
resolved_archetype,
title,
description,
status,
+35 -4
View File
@@ -100,6 +100,8 @@ def ensure_steering_context(
initiative_id: str,
initial_state: Optional[str] = None,
user_id: Optional[str] = None,
method_key: Optional[str] = None,
lifecycle_metadata: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
existing = get_steering_context(tenant_id=tenant_id, initiative_id=initiative_id)
if existing:
@@ -113,6 +115,16 @@ def ensure_steering_context(
)
validate_lifecycle_state(state)
resolved_method = method_key or DEFAULT_METHOD_KEY
from steering.methods.registry import get_method
method = get_method(resolved_method)
if not method:
resolved_method = DEFAULT_METHOD_KEY
method = get_method(resolved_method)
method_version = method.version if method else DEFAULT_METHOD_VERSION
metadata = lifecycle_metadata or {}
conn = get_connection()
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
@@ -129,10 +141,10 @@ def ensure_steering_context(
(
tenant_id,
initiative_id,
DEFAULT_METHOD_KEY,
DEFAULT_METHOD_VERSION,
resolved_method,
method_version,
state,
Json({}),
Json(metadata),
),
)
row = _serialize_row(dict(cur.fetchone()))
@@ -144,7 +156,11 @@ def ensure_steering_context(
"steering_context.created",
user_id=user_id,
tenant_id=tenant_id,
details={"initiative_id": initiative_id, "lifecycle_state": state},
details={
"initiative_id": initiative_id,
"lifecycle_state": state,
"method_key": resolved_method,
},
)
return row
@@ -250,10 +266,25 @@ def create_context_for_new_initiative(
tenant_id: str,
initiative_id: str,
user_id: Optional[str] = None,
archetype_key: str = "initiative.generic",
method_profile_key: Optional[str] = None,
) -> dict[str, Any]:
from entity_archetypes.registry import resolve_default_method_key
from method_profiles.registry import resolve_method_for_profile
method_key = resolve_default_method_key(archetype_key)
lifecycle_metadata: dict[str, Any] = {}
if method_profile_key:
profile_method = resolve_method_for_profile(method_profile_key)
if profile_method:
method_key = profile_method
lifecycle_metadata["method_profile_key"] = method_profile_key
return ensure_steering_context(
tenant_id=tenant_id,
initiative_id=initiative_id,
initial_state="intake",
user_id=user_id,
method_key=method_key,
lifecycle_metadata=lifecycle_metadata or None,
)
+11 -2
View File
@@ -1,9 +1,15 @@
"""Adaptive Steering Core — AP1.0 Foundation."""
"""Adaptive Steering Core — AP1.0 Foundation + AP2.0 methods."""
from __future__ import annotations
from steering.hooks.registry import register_builtin_hooks
from steering.methods.registrations import generic_operating, product_milestone_driven
from steering.methods.registrations import (
ap20_method_stubs,
continuous_product,
generic_operating,
product_milestone_driven,
program_delivery,
)
from steering.strategies.next_action import register_builtin_strategies
@@ -13,6 +19,9 @@ def bootstrap_steering() -> None:
register_builtin_strategies()
generic_operating.register()
product_milestone_driven.register()
program_delivery.register()
continuous_product.register()
ap20_method_stubs.register()
bootstrap_steering()
@@ -0,0 +1,70 @@
"""Shared registration helper for AP2.0 method stubs."""
from __future__ import annotations
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS
from steering.methods.registry import MethodDefinition, get_method, register_method
_PRODUCT_LIKE_STEPS = (
"intake",
"method_selection",
"structure_setup",
"planning",
"action_selection",
"assignment",
"waiting",
"result_intake",
"validation",
"review",
"adaptation",
"closure",
)
_LIGHT_STEPS = (
"intake",
"structure_setup",
"action_selection",
"assignment",
"waiting",
"review",
"adaptation",
"closure",
)
def register_stub_method(
*,
key: str,
label: str,
description: str,
next_action_strategy_key: str = "default",
lifecycle_steps: tuple[str, ...] | None = None,
) -> None:
if get_method(key):
return
register_method(
MethodDefinition(
key=key,
version="0.1.0",
label=label,
description=description,
default_lifecycle_steps=lifecycle_steps or STANDARD_LIFECYCLE_STEPS,
next_action_strategy_key=next_action_strategy_key,
)
)
def register_product_like_method(
*,
key: str,
label: str,
description: str,
next_action_strategy_key: str,
) -> None:
register_stub_method(
key=key,
label=label,
description=description,
next_action_strategy_key=next_action_strategy_key,
lifecycle_steps=_PRODUCT_LIKE_STEPS,
)
@@ -0,0 +1,50 @@
"""AP2.0a — remaining method stubs."""
from __future__ import annotations
from steering.methods.registrations._helpers import register_stub_method
def register() -> None:
register_stub_method(
key="maturity_progression",
label="Reifegrad-Entwicklung",
description="Stufen, Routinen, historische Entwicklung",
next_action_strategy_key="default",
)
register_stub_method(
key="sequential_dependency",
label="Sequenzielle Abhängigkeit",
description="Graph-Pfade, kritischer Pfad (read model)",
next_action_strategy_key="default",
)
register_stub_method(
key="recurring_control",
label="Rhythmus-Steuerung",
description="Dauerprogramm, fällig/überfällig, Abweichungen",
next_action_strategy_key="default",
)
register_stub_method(
key="queue_pull",
label="Inbox / Queue",
description="Pull oder Empfehlung aus Queue",
next_action_strategy_key="default",
)
register_stub_method(
key="agile_iteration",
label="Iterations-Zeitbox",
description="Sprint/work_cycle Profil auf Product/Programm",
next_action_strategy_key="default",
)
register_stub_method(
key="dispute_procedure",
label="Verfahren / Konflikt",
description="Reaktive Steuerung, Fristen, Entscheidungen",
next_action_strategy_key="default",
)
register_stub_method(
key="chapter_based_progression",
label="Kapitel-Entwicklung",
description="Inhaltliche Progression, Reviews",
next_action_strategy_key="default",
)
@@ -0,0 +1,14 @@
"""Built-in method: continuous_product — AP2.0a."""
from __future__ import annotations
from steering.methods.registrations._helpers import register_product_like_method
def register() -> None:
register_product_like_method(
key="continuous_product",
label="Produkt (kontinuierlich)",
description="Kontinuierlicher Betrieb — Ist zuerst, Plan als Orientierung",
next_action_strategy_key="continuous_product",
)
@@ -0,0 +1,14 @@
"""Built-in method: program_delivery — AP2.0a."""
from __future__ import annotations
from steering.methods.registrations._helpers import register_product_like_method
def register() -> None:
register_product_like_method(
key="program_delivery",
label="Programm (begrenzt)",
description="Meilenstein- und gate-orientierte Steuerung mit Abschluss",
next_action_strategy_key="program_delivery",
)
@@ -2,10 +2,18 @@
from __future__ import annotations
from steering.strategies.next_action.continuous_product import (
continuous_product_strategy,
register_continuous_product_strategy,
)
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.program_delivery import (
program_delivery_strategy,
register_program_delivery_strategy,
)
from steering.strategies.next_action.registry import (
get_next_action_strategy,
register_next_action_strategy,
@@ -16,3 +24,5 @@ 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)
register_program_delivery_strategy()
register_continuous_product_strategy()
@@ -0,0 +1,114 @@
"""Continuous product NextAction strategy — AP2.0a (Ist zuerst)."""
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 steering.strategies.next_action.registry import (
get_next_action_strategy,
register_next_action_strategy,
)
from tenant_context import TenantContext
_default = DefaultNextActionStrategy()
_OPEN_ACTION = ("open", "ready", "in_progress", "blocked", "review_required")
class ContinuousProductStrategy:
key = "continuous_product"
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
'action' AS kind,
a.title AS title,
'Offenes Arbeitspaket priorisieren' AS summary,
a.initiative_id,
a.id AS action_id,
NULL::uuid AS backlog_item_id,
'open_action_priority' AS reason_code,
'Als Nächstes ausführen' AS recommended_action
FROM actions a
WHERE a.tenant_id = %s AND a.initiative_id = %s
AND a.status = ANY(%s)
ORDER BY
CASE a.status
WHEN 'blocked' THEN 0
WHEN 'review_required' THEN 1
WHEN 'in_progress' THEN 2
WHEN 'ready' THEN 3
ELSE 4
END,
CASE a.priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 ELSE 2 END,
a.due_at ASC NULLS LAST,
a.updated_at DESC
LIMIT %s
""",
(ctx.tenant_id, initiative_id, list(_OPEN_ACTION), limit),
)
for row in cur.fetchall():
item = dict(row)
item["initiative_id"] = str(item["initiative_id"])
item["action_id"] = str(item["action_id"])
candidates.append(item)
finally:
conn.close()
remaining = limit - len(candidates)
if remaining > 0:
from steering.strategies.next_action.product_milestone_driven import (
ProductMilestoneDrivenStrategy,
)
gate_items = ProductMilestoneDrivenStrategy().evaluate(
ctx, initiative_id=initiative_id, limit=remaining
)
for item in gate_items:
if item.get("kind") == "review_milestone":
candidates.append(item)
remaining -= 1
if remaining <= 0:
break
if len(candidates) < limit:
rest = default_rules.get_next_action_candidates_for_initiative(
ctx, initiative_id=initiative_id, limit=limit - len(candidates)
)
seen = {c.get("action_id") for c in candidates if c.get("action_id")}
for item in rest:
if item.get("action_id") and item["action_id"] in seen:
continue
candidates.append(item)
if len(candidates) >= limit:
break
return candidates[:limit]
continuous_product_strategy = ContinuousProductStrategy()
def register_continuous_product_strategy() -> None:
if not get_next_action_strategy(continuous_product_strategy.key):
register_next_action_strategy(continuous_product_strategy)
@@ -0,0 +1,28 @@
"""Program delivery NextAction strategy — AP2.0a (Gate-Horizont)."""
from __future__ import annotations
from steering.strategies.next_action.product_milestone_driven import (
ProductMilestoneDrivenStrategy,
)
from steering.strategies.next_action.registry import (
get_next_action_strategy,
register_next_action_strategy,
)
_strategy = ProductMilestoneDrivenStrategy()
class ProgramDeliveryStrategy:
key = "program_delivery"
def evaluate(self, ctx, *, initiative_id=None, limit=10):
return _strategy.evaluate(ctx, initiative_id=initiative_id, limit=limit)
program_delivery_strategy = ProgramDeliveryStrategy()
def register_program_delivery_strategy() -> None:
if not get_next_action_strategy(program_delivery_strategy.key):
register_next_action_strategy(program_delivery_strategy)
@@ -49,7 +49,11 @@ def test_list_entity_archetypes(client):
)
assert res.status_code == 200
keys = {item["key"] for item in res.json()}
assert keys == {"initiative.generic", "initiative.program", "initiative.product"}
assert "initiative.generic" in keys
assert "initiative.program" in keys
assert "initiative.product" in keys
assert "initiative.maturity_journey" in keys
assert "initiative.content_project" in keys
def test_invalid_archetype_rejected(client):
@@ -0,0 +1,104 @@
"""AP2.0 — Method registry, Archetyp defaults, Project mirror."""
from __future__ import annotations
from auth import AUTH_HEADER
from steering.methods.registry import list_methods
from tests.factories import provision_user_in_tenant
from tests.test_initiatives_actions import _auth, _create_initiative, _login
def test_ap20_all_methods_registered():
keys = {m.key for m in list_methods()}
assert "generic_operating" in keys
assert "product_milestone_driven" in keys
assert "program_delivery" in keys
assert "continuous_product" in keys
assert "maturity_progression" in keys
assert "chapter_based_progression" in keys
assert "agile_iteration" in keys
def test_product_initiative_gets_continuous_product_method(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
created = _create_initiative(
client,
token,
title="Kairo Product",
archetype_key="initiative.product",
)
assert created.status_code == 201
initiative_id = created.json()["id"]
snap = client.get(
f"/api/initiatives/{initiative_id}/steering-snapshot",
headers=_auth(token),
)
assert snap.status_code == 200
body = snap.json()
assert body["method_key"] == "continuous_product"
assert body["archetype_key"] == "initiative.product"
assert body.get("archetype_label")
assert body.get("steering_guidance")
def test_program_initiative_gets_program_delivery_method(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
created = _create_initiative(
client,
token,
title="Release Program",
archetype_key="initiative.program",
)
assert created.status_code == 201
initiative_id = created.json()["id"]
ctx = client.get(
f"/api/steering/initiatives/{initiative_id}/context",
headers=_auth(token),
)
assert ctx.status_code == 200
assert ctx.json()["method_key"] == "program_delivery"
def test_project_inherits_mirror_archetype(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
created = _create_initiative(
client,
token,
title="Mirror Test",
archetype_key="initiative.product",
)
initiative_id = created.json()["id"]
project = client.post(
f"/api/initiatives/{initiative_id}/projects",
json={"title": "Product Stream"},
headers=_auth(token),
)
assert project.status_code == 201
assert project.json()["archetype_key"] == "project.product"
def test_entity_archetypes_include_ap20_portfolio(client):
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
res = client.get(
"/api/entity-archetypes?entity_type=initiative",
headers=_auth(token),
)
assert res.status_code == 200
keys = {item["key"] for item in res.json()}
assert "initiative.maturity_journey" in keys
assert "initiative.content_project" in keys
assert "initiative.product" in keys
sample = next(i for i in res.json() if i["key"] == "initiative.product")
assert sample.get("default_method_key") == "continuous_product"
+2 -2
View File
@@ -1,3 +1,3 @@
APP_VERSION = "0.17.0-ap1.5d"
DB_SCHEMA_VERSION = "018"
APP_VERSION = "0.18.0-ap2.0"
DB_SCHEMA_VERSION = "019"
APP_NAME = "jinkendo-kairo"