Skip to content

feat(cli): render markdown in responses with auto-detection - #5980

Closed
pedronalis wants to merge 2 commits into
NousResearch:mainfrom
pedronalis:feat/markdown-rendering-clean
Closed

feat(cli): render markdown in responses with auto-detection#5980
pedronalis wants to merge 2 commits into
NousResearch:mainfrom
pedronalis:feat/markdown-rendering-clean

Conversation

@pedronalis

Copy link
Copy Markdown

Summary

Render AI responses as Rich Markdown instead of raw text, so **bold**, - lists, code blocks display properly formatted in the terminal.

Changes

cli.py

  • Add _rich_markdown_from_text() using rich.markdown.Markdown for proper rendering
  • Add _smart_render() that auto-detects markdown syntax and routes to appropriate renderer
  • Updated 3 response rendering points (main responses, /plan, /btw)
  • Falls back to _rich_text_from_ansi() for plain text (no markdown syntax detected)

tests/cli/test_markdown_rendering.py (new)

  • 5 static tests verifying functions exist and are used
  • 4 integration tests verifying Rich Markdown renders correctly

Approach

Unlike PR #2650, this implementation:

  • No config flag needed — markdown detection is automatic
  • Simpler code — 25 lines vs 199 lines
  • No streaming re-render complexity — works for non-streaming responses
  • Graceful fallback — plain ANSI for responses without markdown

Test plan

  • Static tests pass (function existence, import checks)
  • Integration tests verify Rich Markdown rendering
  • Manual: run hermes and confirm markdown renders properly

Comparison to PR #2650

Aspect #2650 This PR
Files changed 2 2
Lines +199 / -18 +25 / -3
Commits 6 2
Config flag No No
Streaming support Yes (complex) No (simpler)
Tests 8 9

This PR is a minimal, focused implementation. Streaming support can be added later if needed.

Add _rich_markdown_from_text() using rich.markdown.Markdown for proper
rendering of headers, code blocks, tables, lists, and syntax highlighting.

Add _smart_render() that auto-detects markdown syntax and routes to
appropriate renderer (Markdown vs ANSI text).

Updated 3 response rendering points:
- Main agent responses (line ~6670)
- Background tasks /plan (line ~4770)
- /btw command (line ~4893)

No config flag needed — markdown detection is automatic based on syntax
presence. Falls back to ANSI rendering for plain text responses.
Add 5 inspection tests verifying:
- rich.markdown.Markdown import exists
- _rich_markdown_from_text function defined
- _smart_render auto-detection function defined
- Markdown syntax markers detected
- Fallback to ANSI rendering present
- Response Panel rendering updated

Add 4 integration tests verifying Rich Markdown actually renders:
- Bold text (no raw asterisks)
- Code blocks (no raw backticks)
- Headers (no raw ##)
- Lists (proper bullets)
@blasai1739217-cmyk

Copy link
Copy Markdown

Friendly bump on this PR in case it fell through the cracks \u2014 would love a review when someone has a minute. Thanks!

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution! This PR's core feature — rendering AI responses with rich.markdown.Markdown — is already implemented on main and shipped in v2026.4.23.

This is an automated hermes-sweeper review.

Evidence:

  • cli.py:1239_render_final_assistant_content() uses rich.markdown.Markdown and supports three modes: render, strip, and raw
  • hermes_cli/config.py:634display.final_response_markdown config key defaults to strip; set it to render to get full Rich Markdown output
  • Commit 177e6eb3d wired markdown rendering into all three response rendering points (main responses, /btw, background tasks) including streaming
  • tests/cli/test_cli_markdown_rendering.py already covers the same rendering helpers
  • Shipped in release v2026.4.23

The existing implementation is a superset of this PR: it adds streaming support and a config-controlled mode rather than auto-detection heuristics. Closing as already implemented.

@teknium1 teknium1 closed this Apr 27, 2026
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #12836 and #5084 — earlier Rich Markdown rendering PRs. This is a simpler alternative without streaming support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants