Commit Graph

5 Commits

  • feat(agent): Add /tokens command for cumulative token usage tracking
    Added /tokens slash command to TUI that displays session-wide token statistics.
    Key changes:
    - Fixed SessionManager to accumulate token usage instead of storing only last event
    - Added cumulative token tracking to TUI renderer alongside per-request totals
    - Implemented slash command infrastructure with /tokens autocomplete support
    - Fixed file autocompletion that was missing from Tab key handling
    - Clean minimal display format showing input/output/reasoning/cache/tool counts
    
    The /tokens command shows:
    Total usage
       input: 1,234
       output: 567
       reasoning: 89
       cache read: 100
       cache write: 50
       tool calls: 2
  • fix(tui): Fix garbled output when content exceeds viewport
    - Implemented new renderLineBased method that properly handles scrollback boundaries
    - Fixed ANSI code preservation in MarkdownComponent line wrapping
    - Added comprehensive test to reproduce and verify the fix
    - Root cause: PARTIAL rendering strategy couldn't position cursor in scrollback
    - Solution: Component-agnostic line comparison with proper viewport boundary handling
  • fix(tui): Container change detection for proper differential rendering
    Fixed rendering artifact where duplicate bottom borders appeared when components
    dynamically shifted positions (e.g., Ctrl+C in agent clearing status container).
    
    Root cause: Container wasn't reporting as "changed" when cleared (0 children),
    causing differential renderer to skip re-rendering that area.
    
    Solution: Container now tracks previousChildCount and reports changed when
    child count changes, ensuring proper re-rendering when containers are cleared.
    
    - Added comprehensive test reproducing the layout shift artifact
    - Fixed Container to track and report child count changes
    - All tests pass including new layout shift artifact test
  • tui-double-buffer: Implement smart differential rendering with terminal abstraction
    - Create Terminal interface abstracting stdin/stdout operations for dependency injection
    - Implement ProcessTerminal for production use with process.stdin/stdout
    - Implement VirtualTerminal using @xterm/headless for accurate terminal emulation in tests
    - Fix TypeScript imports for @xterm/headless module
    - Move all component files to src/components/ directory for better organization
    - Add comprehensive test suite with async/await patterns for proper render timing
    - Fix critical TUI differential rendering bug when components grow in height
      - Issue: Old content wasn't properly cleared when component line count increased
      - Solution: Clear each old line individually before redrawing, ensure cursor at line start
    - Add test verifying terminal content preservation and text editor growth behavior
    - Update tsconfig.json to include test files in type checking
    - Add benchmark test comparing single vs double buffer performance
    
    The implementation successfully reduces flicker by only updating changed lines
    rather than clearing entire sections. Both TUI implementations maintain the
    same interface for backward compatibility.