TeamB

id: task-41 title: 'CLI: Migrate terminal UI to bblessed' status: Done assignee:

  • Claude created_date: '2025-06-11' labels:
  • cli dependencies: []

Description

Migrate all CLI interfaces to bblessed for a consistent terminal experience.

Acceptance Criteria

  • [x] Init wizard uses bblessed forms and lists
  • [x] Task view uses bblessed components
  • [x] Doc view uses bblessed components
  • [x] Board view rendered with bblessed
  • [x] Remove prompts-based UI code
  • [x] Works on Node and Bun

Implementation Notes

Successfully migrated all terminal UI elements to use the bblessed library from GitHub (context-labs/bblessed), which is a Bun-optimized fork of blessed. This migration eliminated the need for the Windows terminfo patch script that was previously required.

Key Design Decisions:

  1. Dynamic Loading with Runtime Detection:

    • Blessed is loaded via dynamic imports in loadBlessed() function
    • Checks output.isTTY before attempting to load to avoid issues in non-interactive environments
    • Returns null on load failure, enabling seamless fallback behavior
  2. Graceful Fallback Strategy:

    • promptText(): Falls back to readline's createInterface for basic text input
    • multiSelect(): Returns empty array when blessed unavailable (non-interactive default)
    • scrollableViewer(): Falls back to simple console.log output
    • Ensures CI/CD pipelines and non-TTY environments continue to work
  3. Type Safety Without Hard Dependencies:

    • Created src/types/blessed.d.ts with intentional any type to allow optional runtime loading
    • Used @ts-ignore comment for dynamic import to prevent TypeScript compilation errors
    • This approach keeps blessed as a truly optional dependency
  4. Modular TUI Architecture:

    • Centralized all TUI logic in src/ui/tui.ts for consistency and maintainability
    • Each function is self-contained with its own fallback logic
    • Created separate src/ui/board.ts for board-specific rendering logic

Implementation Details:

File Structure Changes:

  • Created src/ui/tui.ts - Core TUI wrapper functions
  • Created src/ui/board.ts - Board-specific TUI rendering
  • Created src/types/blessed.d.ts - TypeScript declarations
  • Modified src/cli.ts - Integrated TUI functions and added --tui flags

Command Modifications:

  • Init Command:

    • Replaced readline prompts with promptText() for project/reporter name
    • Replaced basic prompt with multiSelect() for agent file selection
    • Removed dependency on prompts package entirely
  • View Commands (task/doc/board):

    • Added --tui option to all view commands
    • When flag is present, content is displayed in scrollable blessed box
    • Maintains original output format when flag is absent

Package Updates:

  • Removed: prompts package (no longer needed)
  • Added: blessed from github:context-labs/bblessed (Bun-optimized fork)
  • Removed: scripts/patch-blessed.js (no longer needed with bblessed)
  • Removed: resources/terminfo/ directory (bundled terminfo no longer required)
  • Updated: bun.lock and package.json accordingly

Technical Implementation:

Blessed Widget Configuration:

  • Text input: Centered form with bordered textbox, handles Enter/Escape keys
  • Multi-select: List widget with checkbox-style indicators, Space toggles, Enter confirms
  • Scrollable viewer: Full-screen box with vi-style navigation (j/k, arrows), q/Escape to exit
  • All widgets support mouse interaction where available

Error Handling:

  • Try-catch blocks around dynamic imports prevent crashes
  • Fallback mechanisms activate automatically on any failure
  • No error messages shown to users - seamless degradation

Testing and Compatibility:

  • All 140 tests pass without modification
  • Tests run successfully without blessed installed (using fallbacks)
  • Verified compatibility with both Node.js and Bun runtimes
  • No breaking changes to existing CLI behavior
Brodocs MVP