From Monolithic Package to Plugin Tree: A Pluggable Architecture for Terminal UIs

    Learn how to model a terminal UI (TUI) as a composable plugin tree instead of a monolithic package. This article breaks down rendering, interaction, domain, and composition nodes, covers incremental streaming rendering, multi-prefix completion, status bar design, theme hot-swapping, extension seams, and a practical migration path for plugin developers.

    1. The Starting Point: Why Terminal UIs Degrade into Monoliths

    In the ecosystem of AI coding assistants, the terminal interaction UI (TUI) has long been treated as a second-class citizen. Most implementations cram session rendering, input handling, command parsing, and status display into a single module: changing a color scheme requires touching core code, removing an unused status bar item means commenting out several lines, and adding a custom command requires understanding the entire render loop. As capabilities grow, the package quickly balloons into an entangled whole that you are afraid to delete or modify.

    The root cause is not the terminal itself, but treating “the interface” as an indivisible delivery unit. As long as the delivery unit is a single package, extension can only happen by modifying it; and as long as extension requires modifying it, a plugin ecosystem cannot emerge.

    2. The Core Idea: The UI Is Not a Package, but a Composable Plugin Tree

    A better model is this: the TUI is a plugin tree hosted by a plugin runtime, where each node does exactly one thing and nodes collaborate through well-defined seams. Under this model, a usable terminal UI can be decomposed into at least four categories of nodes:

    • Rendering nodes: responsible for drawing a given kind of content in a given form—for example, streaming text, tool call cards, diff views, and terminal output blocks.
    • Interaction nodes: responsible for capturing and interpreting user input—for example, slash commands, shell passthrough, file references, skill completion, and clipboard image pasting.
    • Domain nodes: UI-agnostic business logic—for example, session state machines, context budgeting, tool scheduling, and permission decisions.
    • Composition nodes: decide which nodes are assembled and in what layout and order—for example, status bar item collections and side panel groups.

    This decomposition yields three immediate benefits. Omittable: capabilities you don’t need simply aren’t assembled, rather than being assembled and then hidden. Hot-swappable: replacing a rendering implementation means swapping the corresponding node, leaving domain state untouched. Testable: domain nodes can be unit-tested in a terminal-free environment, while rendering nodes are locked down with snapshot tests.

    3. Implementation Notes for Key Capabilities

    3.1 Incremental Rendering of Streaming Session Records

    The hard part of streaming output is not speed, but “avoiding re-layout of already-settled content during incremental updates.” A workable strategy models each message as a mutable buffer plus a render cache: when text deltas arrive, only the trailing few lines are redrawn; Markdown structures (headings, lists, code fences) are promoted to stable blocks only after they are closed. Tool calls are rendered as standalone cards, with the card body dispatched by type—diff content gets line-level add/remove coloring, command output is rendered as monospace blocks with truncation and folding for long lines. This way, the rendering cost of a long session is roughly proportional to newly added content, not to the total history length.

    3.2 Multimodal Completion in the Input Editor

    The editor needs to support multiple “syntax prefixes” in a single input box: slash triggers command completion, exclamation mark triggers shell passthrough, @ triggers file path completion, and hash triggers skill or prompt template completion. In engineering terms, prefix recognition should be an extensible trigger rule table, where each rule declares its prefix character, completion source, and argument parsing style—allowing third-party nodes to register their own prefixes without modifying the editor core. Clipboard image pasting depends on the terminal’s image protocol support; when unavailable, it should degrade to inserting a file path rather than erroring out.

    3.3 Status Bar and Docked Panels

    The status bar is suited for “low-frequency, always-visible” information: current model, session mode (normal / plan / elevated auto-execution), VCS branch, and context usage ratio. Docked panels suit “expand-on-demand” information: activity streams, to-do lists, side-channel Q&A, and subagent groups. Both share one constraint: refresh frequency. Status bar items should declare their own refresh triggers to avoid full recomputation every frame—especially for metrics like context usage that require token counting.

    3.4 Theme Hot-Swapping

    To make theme switching offer “live preview without losing state,” the key is making the color scheme an injectable dependency rather than a global constant. All rendering nodes fetch colors from a theme context; on switch, a single theme-change event is broadcast. Custom themes are provided as key-value mappings, with unoverridden keys falling back to the built-in baseline. Dark, light, and auto-follow-system modes are simply different presets of the same mechanism.

    4. The Extension Mechanism: Seams Instead of Core Modifications

    Extensibility comes from a small set of stable, semantically clear registration seams. Illustrative pseudocode (structure only, not any specific product API):

    1. // Register a slash command
    2. ctx.command({
    3. name: 'theme',
    4. args: '[name]',
    5. run: (args, session) => themeApi.preview(args.name ?? 'auto'),
    6. });
    7. // Register a status bar item with a declared refresh condition
    8. ctx.statusbar({
    9. id: 'ctx-usage',
    10. render: (s) => `ctx ${s.contextUsagePercent}%`,
    11. refresh: (s, prev) => s.contextUsagePercent !== prev.contextUsagePercent,
    12. });
    13. // Register an editor prefix enhancement
    14. ctx.inputEnhancer({
    15. prefix: '#',
    16. complete: (q) => skillIndex.search(q),
    17. });

    A simple test of whether a set of seams is well designed: does the core team also use only these seams when extending the tool’s own capabilities? If the core takes internal shortcuts while third parties must use public interfaces, the ecosystem will inevitably fork.

    5. A Migration Path for Plugin Developers

    The core conflict in migrating existing plugins is that logic and rendering are written together. A workable path has three steps.

    Step one: identify boundaries. Use static scanning to find code tightly coupled to the terminal: direct writes to standard output, layout calculations that depend on terminal dimensions, hardcoded ANSI escape sequences, and handlers bound to specific keys. These are rendering-related code; the rest is mostly domain code.

    Step two: push the domain down. Keep domain logic in a domain package whose interface exposes only data and events—no drawing behavior. The acceptance criterion: the package can be fully unit-tested in a terminal-free environment.

    Step three: add adapters. Write a terminal adapter package that maps domain capabilities to rendering and interaction nodes. The same domain package can simultaneously be adapted for a graphical UI, avoiding two sets of business logic.

    The real value migration tooling can provide is automatically generating decomposition suggestions and adapter skeletons, compressing human judgment down to a single “confirm the boundaries” step.

    6. Engineering Considerations

    • Terminal capability differences: image protocols, true color, and mouse events vary across terminals; capability detection and fallback paths are mandatory.
    • Versioning and distribution: preview capabilities are best shipped through a separate pre-release channel that must be explicitly specified at install time. First launch downloads the dependency tree, which can be slow on weak connections—provide progress feedback and offline caching.
    • Observability: the plugin tree structure should be exportable, making it easier to diagnose issues like “a node was not assembled” or “a seam was overridden.”
    • Permission boundaries: elevated auto-execution mode must come with allowlists, audit logging, and one-click downgrade; the secure default should always be the most conservative option.

    7. Terminal and Graphical UIs Are Not Substitutes

    Once the domain layer is properly separated, the terminal UI and the graphical UI are simply two ways of composing the same capabilities. Task boards, version history graphs, file browsing, remote session access, and real-time usage statistics are all, at bottom, composition-layer nodes—presented as panels and commands in the terminal, and as views in the graphical interface. The measure of a successful architecture is not how flashy the interface looks, but that adding a new presentation layer requires almost zero changes to business code.

    8. A Landing Checklist

    1. Draw the plugin tree first: list the four node categories—rendering, interaction, domain, composition—and their dependency directions.
    2. Define the seams: commands, status bar items, input enhancements, theme keys—few and stable at first.
    3. Enforce domain purity: no drawing or key handling in the domain package.
    4. Implement capability detection: degrade gracefully when terminal features are missing.
    5. Build a migration scanner: automatically identify rendering-coupled code and generate adapter skeletons.
    6. Backstop security: pair elevated-permission mode with auditing and fast rollback.
    7. Bootstrap with your own seams: extend the tool using the same registration points to verify ecosystem consistency.