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 by InputStateMachine. Interface defined in :core:domain, default implementation DefaultShortcutRegistry provided by TuiModule.

  • RendererRegistry: Holds custom ToolRenderer, EntryRenderer, MessageRenderer, and MarkdownTransformer instances registered by extensions via ExtensionAPI. Provided as @SingleIn in TuiModule.

  • StatusBarRegistry: Holds extension-contributed status items (StatusItem.Text, StatusItem.Widget, StatusItem.Flow) rendered in the status bar row. Uses a synchronized LinkedHashMap snapshot 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 using AtomicReference state holding for lock-free concurrent updates.

  • ActiveProgressRegistry: Manages active extension progress task handles and drives dirty-state notifications for TuiRenderCoordinator.

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.