feat: Render Markdown in chat and query output using rich#22
feat: Render Markdown in chat and query output using rich#22KylinMountain wants to merge 6 commits intomainfrom
Conversation
Use rich's Live + Markdown to progressively render LLM responses in the chat REPL with proper formatting (headings, bold, code blocks, lists, etc.) instead of raw text output. Falls back to plain text when --no-color is set. Tool call lines still use prompt_toolkit styled output.
Apply the same rich Live + Markdown streaming render to `openkb query` as was added to chat. Falls back to plain text when stdout is not a tty.
f206c75 to
5d2b4b4
Compare
Code reviewFound 1 issue:
Lines 153 to 160 in 5d2b4b4 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
- Create a fresh Live instance after each tool call instead of
stop/start on the same instance, preventing the auto-refresh
thread from overwriting stdout text with CURSOR_UP sequences
- Respect NO_COLOR env var in query.py (consistent with chat.py)
- Fix print("\n") → print() in chat.py finally block to avoid
extra blank line when Live is active
Custom Rich Theme: bold headings without color, dark background for inline code, subtle link/list/blockquote colors. Shared via _make_rich_console() used by both chat and query.
- Headings: blue (#5fa0e0) - Code: yellow-ish on dark background - List bullets: green (#6ac0a0) - Bold: bright white, italic: light gray - Paragraph text: light gray for visibility
Code reviewFound 1 issue:
Lines 276 to 303 in 8cdc5a7
Lines 150 to 168 in 8cdc5a7 Fix: use a separate display buffer that resets when Live is restarted, while keeping 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |

Summary
rich.live.Live+rich.markdown.Markdownto progressively render LLM responses with proper terminal formatting (headings, bold, code blocks, lists, etc.)openkb chat(interactive REPL) andopenkb query(single-shot)--no-coloris set (chat) or stdout is not a tty (query)rich>=13.0as an explicit dependencyTest plan
python -m pytest tests/— 197 passedopenkb chat— verify headings, bold, code blocks render with formattingopenkb chat --no-color— verify plain text fallbackopenkb query "question"— verify formatted outputopenkb query "question" > file.txt— verify no ANSI codes in file