Skip to content

feat(cli): 终端输出支持 Markdown 渲染(表格/代码块/列表) - #123

Open
GrantDuan wants to merge 2 commits into
MiniMax-AI:mainfrom
GrantDuan:feat/markdown-renderer-v2
Open

GrantDuan wants to merge 2 commits into
MiniMax-AI:mainfrom
GrantDuan:feat/markdown-renderer-v2

Conversation

@GrantDuan

@GrantDuan GrantDuan commented Sep 11, 2026

Copy link
Copy Markdown

Closes #121

改动内容

CLI 模式下助手回复原来通过 print() 原样输出,Markdown 表格/代码块显示为原始标记。本次新增一个渲染层(仅 2 个提交,基于最新 main):

  • 新增 mini_agent/utils/markdown_renderer.py(commit 1)
    • has_markdown(text):高精度启发式检测,宁可漏过、不可误判——只识别结构性、无歧义构造(表格 / fenced code block / ATX 标题 / 列表),不检测行内标记(**加粗**行内代码__下划线__),因为它们极易误判(__init__.py 被当加粗、2 ** 3 吞运算符)。漏检只是按纯文本打印(无害),误检会破坏原文。
    • display_assistant_text(text):命中则用 rich.markdown.Markdown 渲染,否则原样 print()
    • 新增 rich>=13.0.0 依赖
  • agent.py CLI 输出路径接入 display_assistant_text
  • ACP 路径不变:保持原文发送,由客户端负责渲染;会话历史保存原文
  • (commit 2)项目级固定 PyPI 清华镜像源并重新 lock,独立 chore 提交

测试

  • 新增 tests/test_markdown_renderer.py,20 个用例全部通过:
    • 正例:表格 / fence(``` 与 ~~~)/ 标题 / 有序与无序列表
    • 负例:__init__.py__init__/__call__2 ** 3、孤立反引号、散文中的 |#1、缩进注释等不误判

Pull Request 检查清单

  • 代码遵循项目规范(PEP 8、类型注解、docstring)
  • 所有测试通过
  • 添加了必要的测试(20 个新用例)
  • 提交消息清晰(feat / chore 分开)
  • 没有不相关的更改(基于最新 main,仅含本功能相关提交)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Grant Duan and others added 2 commits September 11, 2026 16:31
新增 markdown_renderer 工具模块,CLI 输出助手回复时检测 Markdown 结构化
语法(表格/fenced code block/标题/列表),命中则通过 rich.markdown 渲染,
纯文本保持原样打印。

检测为高精度启发式:宁可漏过(Markdown 按纯文本打印,无害),不可误判
(rich 渲染会破坏原文,如 __init__.py 被加粗),因此不检测行内标记。

- 新增 mini_agent/utils/markdown_renderer.py,新增 rich 依赖
- agent.py CLI 输出路径接入 display_assistant_text
- ACP 路径保持原文发送,由客户端渲染
- 新增 tests/test_markdown_renderer.py 20 个用例

Closes MiniMax-AI#121

Co-Authored-By: Claude Code <noreply@anthropic.com>
uv.lock 记录每个包的来源 URL,index 配置不属于个人机器环境而应提交到
项目,否则不同成员 lock 会产生来回漂移的 URL diff。

- pyproject.toml 添加 [[tool.uv.index]] 指向 pypi.tuna.tsinghua.edu.cn
- 重新 uv lock,全部来源 URL 切换至清华源

Co-Authored-By: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): 终端输出支持 Markdown 渲染(表格/代码块/列表)

1 participant