feat: add terminal UI with Bubble Tea v2#12
Conversation
Implement `yantra tui` — a polished terminal chat UI that connects to the gateway server via WebSocket. The TUI starts the gateway in-process (goroutine), then renders streaming responses, tool progress, and session management in an alternate-screen Bubble Tea app. New files in internal/tui/: - app.go: root Model composing header, chat viewport, input, status bar - chat.go: message rendering with streaming cursor, tool spinners, glamour markdown - client.go: WebSocket client with reconnect and exponential backoff - commands.go: slash command parser (/new, /sessions, /switch, /cancel, /clear, /help, /quit) - input.go: textarea wrapper with Enter-to-send and dynamic height - markdown.go: glamour wrapper for completed assistant messages - messages.go: tea.Msg types bridging server frames into Bubble Tea - styles.go: adaptive dark/light lipgloss styles with purple branding Dependencies: bubbletea v2, bubbles v2, lipgloss v2, glamour. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoImplement terminal UI with Bubble Tea v2 and WebSocket client
WalkthroughsDescription• Implements full terminal UI with Bubble Tea v2, supporting streaming chat, session management, and slash commands • Adds 8 new TUI component files (~1250 lines) covering app model, chat viewport, WebSocket client, input handling, markdown rendering, and styling • Replaces runTUI stub with complete implementation: starts gateway in-process, polls health endpoint, manages WebSocket connection lifecycle • Adds Charm ecosystem dependencies (Bubble Tea v2, Bubbles v2, Lipgloss v2, Glamour) to go.mod and go.sum Diagramflowchart LR
A["User Input"] --> B["InputModel"]
B --> C["App Model"]
C --> D["Client WebSocket"]
D --> E["Gateway Server"]
E --> F["Provider API"]
F --> G["ServerFrame"]
G --> H["ChatModel"]
H --> I["Viewport Render"]
I --> J["Terminal Display"]
File Changes1. cmd/yantra/main.go
|
Code Review by Qodo
1.
|
…meout, DB leak
1. nil Program: Connect() no longer takes a program arg; AttachProgram()
wires it before Run(). readLoop now receives frames correctly.
2. conn race: readLoop takes the conn as a local argument so it never
races with Close/Reconnect mutating c.conn. sessionID reads also
protected by mutex.
3. Reconnect never triggered: DisconnectedMsg handler now returns
a.client.Reconnect() cmd for automatic exponential-backoff reconnect.
4. Health poll timeout: waitForHealth uses http.Client{Timeout: 1s} so a
stalled request can't block past the overall deadline.
5. DB leak: startGatewayInProcess returns a cleanup func that closes all
opened SQLite databases; runTUI defers it.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix Gemini provider: jsonPropToGeminiSchema now parses the 'items' field for array-type parameters, fixing 400 errors with tools like memory_save that have array properties (tags). - Redesign TUI visuals for a cleaner, modern look: - Replace heavy purple header bar with subtle bordered title line - Use ❯/◆ indicators for user/assistant messages instead of labels - Indented message bodies with 4-space padding - Softer color palette (Monokai-inspired: soft purple, cyan, yellow) - Streaming shows 'thinking...' placeholder then text with ▍ cursor - Tool progress: spinner + yellow name + dimmed status - Errors: ✗ prefix with pink-red text - Remove mouse capture so text selection/copy works natively - Minimal status bar with accent-colored session ID Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move lipgloss.HasDarkBackground() call to runTUI before creating the Bubble Tea program. The terminal query response was arriving after Bubble Tea took over stdin, leaking raw escape sequences into the textarea input. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
yantra tui— a polished terminal chat UI using Bubble Tea v2, Bubbles v2, Lipgloss v2, and Glamour/new,/sessions,/switch,/cancel,/clear,/help,/quit), session management, and adaptive dark/light themingNew files (8 files, ~1250 lines in
internal/tui/)app.gochat.goclient.gocommands.goinput.gomarkdown.gomessages.gotea.Msgtypes bridgingServerFrameevents into Bubble Teastyles.goModified files
cmd/yantra/main.go— ReplacedrunTUIstub with full implementation: starts gateway in-process, polls/health, creates TUI app + WebSocket client, runs Bubble Tea programgo.mod/go.sum— Added Charm ecosystem v2 dependenciesTest plan
go build ./...compiles cleanlygo vet ./...passesgo test ./...— all 7 existing test packages pass (gateway, runtime, memory, provider, tool, types, cmd)go run ./cmd/yantra tui→ type "What is 2+2?" → see streaming response/helpshows command list/sessionslists sessions,/new testcreates one🤖 Generated with Claude Code