Skip to content

feat(cli): add Markdown and syntax-highlighted code block rendering - #5617

Closed
pcomte3 wants to merge 13 commits into
NousResearch:mainfrom
pcomte3:feat/hermes-cli-markdown
Closed

feat(cli): add Markdown and syntax-highlighted code block rendering#5617
pcomte3 wants to merge 13 commits into
NousResearch:mainfrom
pcomte3:feat/hermes-cli-markdown

Conversation

@pcomte3

@pcomte3 pcomte3 commented Apr 6, 2026

Copy link
Copy Markdown

Summary

  • Add real-time Markdown rendering for LLM responses in the Hermes CLI, supporting both streaming and non-streaming display modes
  • Streaming uses a stateful line-by-line processor (MarkdownStreamProcessor) with regex-based ANSI transforms for inline formatting and per-line Pygments highlighting for fenced code blocks
  • Non-streaming uses Rich's Markdown class inside the existing Panel for full AST-based rendering
  • Configurable via display.markdown (default: true) and toggleable at runtime with /markdown (alias /md)

Features

  • Inline formatting: bold, italic, bold+italic, strikethrough, inline code, headers (h1–h4), blockquotes, links, ordered/unordered lists, horizontal rules
  • Fenced code blocks: syntax-highlighted with Pygments, rendered with box-drawing decorators (┌───python───, └───)
  • Pipe tables: buffered and rendered with box-drawing borders, aligned columns (wcwidth-aware for emoji/CJK), bold headers, and mid-border separators
  • Skin-aware: Pygments theme auto-selected based on active skin (monokai, nord, friendly_grayscale), overridable via display.code_theme or per-skin code_theme YAML field
  • LLM fence handling: ```markdown / ```md fences transparently skipped (common LLM behavior of wrapping entire responses)
  • Escaped characters: \*, \_, \~, \` correctly preserved as literal text

Files changed

File Change
hermes_cli/markdown_stream.py New — core module (~500 lines)
cli.py Streaming + non-streaming integration, /markdown command, theme resolver
hermes_cli/config.py display.markdown and display.code_theme defaults
hermes_cli/skin_engine.py code_theme field on SkinConfig
hermes_cli/commands.py /markdown command registration
tests/test_markdown_stream.py New — 52 tests covering all transforms, code blocks, tables, fences, edge cases

Test plan

  • pytest tests/test_markdown_stream.py — 52 tests pass
  • Manual: streaming mode — ask agent to write Python code, verify syntax highlighting streams live
  • Manual: non-streaming mode — verify Rich Markdown renders in Panel
  • Manual: /markdown toggle — flip off, verify raw text; flip on, verify formatted
  • Manual: table with emoji — verify column alignment with double-width characters
  • Manual: LLM wrapping response in ```markdown ``` — verify content renders as markdown, not code

@pcomte3

pcomte3 commented Apr 6, 2026

Copy link
Copy Markdown
Author

@teknium1 This PR adds Markdown rendering support to the Hermes CLI — syntax-highlighted code blocks, inline formatting (bold/italic/headers/lists/etc.), and formatted pipe tables with box-drawing borders. Works for both streaming and non-streaming modes with no new dependencies. Toggleable via /markdown command or display.markdown in config. Would love your feedback!

pcomte3 added 2 commits April 7, 2026 09:11
- Extend header support from h1-h4 to h1-h6
- Stricter fence detection: reject ```text mid-line, require clean ```lang or bare ```
- Protect inline code spans from bold/italic regex corruption (sentinel extraction)
- Conservative bold/italic/strikethrough matching: require non-whitespace boundaries
- Rewrite _apply_inline_markdown with explicit processing order instead of generic loop
- Add 9 new tests for robustness (unmatched markers, mid-text backticks, code protection)
@pcomte3

pcomte3 commented Apr 7, 2026

Copy link
Copy Markdown
Author

Update: 2 additional commits pushed.

  • Removed hardcoded 30s timeout in flush_memories — now reads from auxiliary.flush_memories.timeout in config (fixes repeated disconnects on local LLM servers)
  • Hardened markdown renderer: h5/h6 support, stricter fence detection, inline code protection from bold/italic corruption, unmatched markers pass through safely. 59 tests total.

pcomte3 added 10 commits April 7, 2026 09:39
… renderer

Headers (# through ######) returned early without processing **bold**,
*italic*, or `code` markers in their text content. Now strips these
markers before rendering, so `### 1. **Bug Title**` displays cleanly.
Extract _strip_inline_markers() helper (shared with headers) to remove
**bold**, *italic*, ~~strike~~, and `code` markers from table cell text.
Applied during parsing so column widths are computed on clean text.
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.

2 participants