"""插件契约与注册表。 一切能力插件化(docs/architecture/lingtai-runtime.md §4):插件只通过订阅瀑布节点 与提供能力参与运行,彼此不直接调用。M0 只需注册表与装配骨架,首个真实插件(司命 占位裁决器)随 M5 落地;禁域挂载点在 Kernel,不在插件。 """ from __future__ import annotations from typing import Protocol, runtime_checkable from app.runtime.bus import WaterfallBus @runtime_checkable class Plugin(Protocol): """插件契约:稳定标识 + 版本 + 注册入口。""" @property def name(self) -> str: ... @property def version(self) -> str: ... def register(self, bus: WaterfallBus) -> None: ... class PluginRegistry: """按注册序持有插件;同名插件后注册覆盖前注册(Profile 层叠语义)。""" def __init__(self) -> None: self._plugins: dict[str, Plugin] = {} def register(self, plugin: Plugin) -> None: self._plugins[plugin.name] = plugin def bootstrap(self, bus: WaterfallBus) -> None: for plugin in list(self._plugins.values()): plugin.register(bus) def names(self) -> list[str]: return list(self._plugins)