Kairo-Jinkendo/backend/steering/methods/registry.py

48 lines
1.1 KiB
Python
Raw Normal View History

"""Method Registry — built-in steering methods."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal
_METHODS: dict[str, "MethodDefinition"] = {}
@dataclass(frozen=True)
class MethodDefinition:
key: str
version: str
label: str
description: str
default_lifecycle_steps: tuple[str, ...]
next_action_strategy_key: str = "default"
data_slices: frozenset[str] = frozenset()
compatible_archetype_keys: frozenset[str] | Literal["*"] = "*"
def method_compatible_with_archetype(
method: MethodDefinition, archetype_key: str
) -> bool:
compat = method.compatible_archetype_keys
if compat == "*":
return True
return archetype_key in compat
def register_method(defn: MethodDefinition) -> None:
if defn.key in _METHODS:
raise ValueError(f"Method already registered: {defn.key}")
_METHODS[defn.key] = defn
def get_method(key: str) -> MethodDefinition | None:
return _METHODS.get(key)
def list_methods() -> tuple[MethodDefinition, ...]:
return tuple(_METHODS.values())
def clear_methods_for_tests() -> None:
_METHODS.clear()