Support an overridable default for single-registration hooks (register_as_default)
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Single-registration (only_one_registered) hooks cannot express a built-in default that a plugin overrides. Add a register_as_default registration that provides one.
Complexity: Low Target branch: develop
Context
define_hook(only_one_registered=True)(kolibri/plugins/hooks.py:204) makes a second registration raise (hooks.py:337).- There is no mechanism to disable a specific registered hook, so an overridable default must be expressed at registration time.
- The only current
only_one_registeredhook isThemeHook(kolibri/core/theme_hook.py:29). ThemeHook.get_themehand-rolls the "nothing registered → default" case, falling back to{}.
The Change
- Add a way to register a single-registration hook implementation as the default (e.g.
@register_hook(as_default=True)). - A default registration does not count toward the
only_one_registeredlimit. - Resolution prefers a non-default registration.
- Resolution falls back to the default when no non-default is registered.
- Two non-default registrations still raise, as today.
- Expose the effective implementation via a single accessor (e.g.
registered_hook). - Migrate
ThemeHookto the new mechanism, preserving its current no-registration behaviour.
Out of Scope
- Disabling or unregistering arbitrary hooks.
- Multi-registration (non-single) hooks — behaviour unchanged.
Acceptance Criteria
General
- [ ] A single-registration hook can register one implementation as the default.
- [ ] With only a default registered, resolution returns the default.
- [ ] With a non-default registered, resolution returns the non-default whether or not a default is present.
- [ ] Two non-default registrations still raise.
- [ ]
ThemeHookuses the new mechanism, with unchanged behaviour when no theme is registered.
Testing
- [ ] Unit tests cover default-only, override, no-registration, and two-non-default (raises).
References
- Hook framework —
kolibri/plugins/hooks.py(define_hook,register_hook,only_one_registeredat lines 204/337). ThemeHook—kolibri/core/theme_hook.py.
AI usage
Drafted with Claude Code in an interactive design session. The author made every design decision in dialogue and verified the code references.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.