Coverage for src/lumen/cortex/__init__.py: 100%
7 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-31 18:46 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-31 18:46 +0000
1"""
2Lumen Cortex — the surface that foreign Python code plugs into.
4Lumen loads and hosts the extension, not the other way round. A plugin is a
5class with declared attachment points:
7 from lumen.cortex import AiAttribution, Plugin, hook
9 class SepsisGuard(Plugin):
10 name = "sepsis-guard"
11 version = "1.0.0"
13 @hook("resource.written", resource_type="Observation", timeout_ms=2000)
14 async def on_vitals(self, ctx, observation):
15 history = await ctx.read.search("Observation", patient="Patient/1", _count=20)
16 score = self.model.predict(history)
17 if score < 0.8:
18 return
19 await ctx.write.create(
20 {"resourceType": "Flag", ...},
21 ai=AiAttribution(model="llama3", confidence=score),
22 )
24Everything exported here is the public contract; see :mod:`lumen.cortex.contract`
25for what that promise covers and how it is versioned.
26"""
28from .context import PluginContext, ReadPort, WritePort
29from .contract import (
30 CORTEX_API_VERSION,
31 EVENT_RESOURCE_DELETED,
32 EVENT_RESOURCE_WRITTEN,
33 CortexError,
34 PluginRegistrationError,
35)
36from .operation import OperationInvocation
37from .plugin import HookSpec, OperationSpec, Plugin, hook, operation
38from .provenance import AiAttribution
39from .registry import PluginRegistry, get_plugin_registry
41__all__ = [
42 "CORTEX_API_VERSION",
43 "EVENT_RESOURCE_DELETED",
44 "EVENT_RESOURCE_WRITTEN",
45 "AiAttribution",
46 "CortexError",
47 "HookSpec",
48 "OperationInvocation",
49 "OperationSpec",
50 "Plugin",
51 "PluginContext",
52 "PluginRegistrationError",
53 "PluginRegistry",
54 "ReadPort",
55 "WritePort",
56 "get_plugin_registry",
57 "hook",
58 "operation",
59]