Discovery & Entry Points
Kernle uses Python’simportlib.metadata entry points to discover installed components at runtime. This means plugins, stacks, models, and stack components can be installed as separate packages and automatically found by the core.
How It Works
- A package declares entry points in its
pyproject.toml - When the package is installed, Python’s metadata registry records the entry points
- Kernle’s
discover_*()functions scan the registry for matching groups load_component()imports the class and returns it for instantiation
The Four Entry Point Groups
| Group | Discovers | Used By |
|---|---|---|
kernle.plugins | Plugin implementations (PluginProtocol) | Entity.discover_plugins() |
kernle.stacks | Stack implementations (StackProtocol) | CLI stack selection |
kernle.models | Model implementations (ModelProtocol) | Model binding |
kernle.stack_components | Stack components (StackComponentProtocol) | SQLiteStack auto-loading |
Registration Examples
Each entry point maps a name to amodule:class reference:
- Plugin
- Stack
- Model
- Component
Discovery Functions
Thekernle.discovery module provides four targeted discovery functions plus a catch-all:
DiscoveredComponent
Every discovery result is aDiscoveredComponent dataclass:
| Field | Example |
|---|---|
name | "anthropic" |
group | "kernle.models" |
module | "kernle.models.anthropic" |
attr | "AnthropicModel" |
dist_name | "kernle" |
dist_version | "0.8.0" |
qualname | "kernle.models.anthropic:AnthropicModel" |
How Entity Uses Discovery
WhenEntity.discover_plugins() is called, it:
- Calls
discover_plugins()to scan thekernle.pluginsentry point group - Returns a list of
PluginInfofor each discovered plugin (name, version, description, capabilities) - The CLI
kernle statuscommand shows discovered plugins alongside loaded ones
How SQLiteStack Uses Discovery
SQLiteStack can auto-load stack components from entry points:get_default_components()). But load_components_from_discovery() will also pick up third-party components installed via separate packages.
If a component fails to load (import error, missing dependency), it logs a warning and skips that component — other components still load normally.
CLI Status Display
kernle status shows the current composition, including discovered components:
Building a Discoverable Package
To make your plugin, model, or component automatically discoverable:- Implement the relevant protocol
- Add entry point registration to
pyproject.toml - Install the package (
pip install .orpip install -e .) - Kernle discovers it on next startup
pip install kernle-mymodel, running discover_models() will include my-model in the results.