Registry Architecture & DI Scoping
Overview
All TUI registry components are organized under us.nineworlds.book.cli.tui.registry and scoped as @SingleIn(AppScope::class) singletons via Metro DI (TuiModule).
Component Structure
The following registries manage UI and extension contribution states:
-
ShortcutRegistry: Manages keyboard shortcut bindings registered by extension scripts and queried byInputStateMachine. Interface defined in:core:domain, default implementationDefaultShortcutRegistryprovided byTuiModule. -
RendererRegistry: Holds customToolRenderer,EntryRenderer,MessageRenderer, andMarkdownTransformerinstances registered by extensions viaExtensionAPI. Provided as@SingleIninTuiModule. -
StatusBarRegistry: Holds extension-contributed status items (StatusItem.Text,StatusItem.Widget,StatusItem.Flow) rendered in the status bar row. Uses a synchronizedLinkedHashMapsnapshot strategy to preserve stable insertion order across frame renders. -
UiSlotRegistry: Manages slot widget contributions interleaved into the TUI grid layout across standard UI slots (HEADER,ABOVE_PROMPT,BELOW_PROMPT,FOOTER). -
FooterRegistry: Thread-safe registry for custom footer renderers usingAtomicReferencestate holding for lock-free concurrent updates. -
ActiveProgressRegistry: Manages active extension progress task handles and drives dirty-state notifications forTuiRenderCoordinator.
Metro Dependency Injection
All 6 registry singletons are bound in us.nineworlds.book.cli.di.TuiModule:
@SingleIn(AppScope::class)
@Provides
fun provideShortcutRegistry(): ShortcutRegistry = DefaultShortcutRegistry()
@SingleIn(AppScope::class)
@Provides
fun provideRendererRegistry(): RendererRegistry = RendererRegistry()
@SingleIn(AppScope::class)
@Provides
fun provideStatusBarRegistry(): StatusBarRegistry = StatusBarRegistry()
@SingleIn(AppScope::class)
@Provides
fun provideUiSlotRegistry(): UiSlotRegistry = UiSlotRegistry()
@SingleIn(AppScope::class)
@Provides
fun provideFooterRegistry(): FooterRegistry = FooterRegistry()
@SingleIn(AppScope::class)
@Provides
fun provideActiveProgressRegistry(): ActiveProgressRegistry = ActiveProgressRegistry()
By providing these as @SingleIn singletons, all callers (Tui, InputStateMachine, MessageListRenderer, BookScriptReceiver, MordantExtensionUI, RenderFrameBuilder, StatusBarRenderer) receive identical shared instances, preventing silent disconnected registrations.