fix(cli): thread read — nested markdown breaks heading hierarchy #459

Closed
opened 2026-05-24 07:33:52 +00:00 by xiaoju · 1 comment
Owner

问题

uwf thread read 输出的 markdown 中,每个 step 的 Content 部分直接包含 agent 的原始 markdown 输出。这些输出里的 ### 标题会和外层的 heading 层级冲突:

# Thread                        ← 顶层
## Step 1: planner              ← step 层
### Content
# Analysis Complete             ← agent 输出的 h1,破坏了层级
## Issue Summary                ← agent 输出的 h2,跟 step 层平级

期望

Content 内嵌的 markdown heading 应该降级,保持层级正确。例如 Content 在 ### 下面,那么内容里的 # 应该变成 ###### 变成 #####,以此类推。

或者用其他方式隔离(比如 code block / blockquote),但降级 heading 最自然。

涉及文件

  • packages/cli-workflow/src/commands/thread.tsformatThreadReadMarkdown 函数
## 问题 `uwf thread read` 输出的 markdown 中,每个 step 的 Content 部分直接包含 agent 的原始 markdown 输出。这些输出里的 `#`、`##` 标题会和外层的 heading 层级冲突: ```markdown # Thread ← 顶层 ## Step 1: planner ← step 层 ### Content # Analysis Complete ← agent 输出的 h1,破坏了层级 ## Issue Summary ← agent 输出的 h2,跟 step 层平级 ``` ## 期望 Content 内嵌的 markdown heading 应该降级,保持层级正确。例如 Content 在 `###` 下面,那么内容里的 `#` 应该变成 `####`,`##` 变成 `#####`,以此类推。 或者用其他方式隔离(比如 code block / blockquote),但降级 heading 最自然。 ## 涉及文件 - `packages/cli-workflow/src/commands/thread.ts` — `formatThreadReadMarkdown` 函数
Author
Owner

设计方案:XML Tag 隔离

放弃 heading demotion 方案(需正确解析 markdown、h6 上限问题)。改用自定义 XML tag 包裹 prompt 和 output:

## Step 1: planner `ER9Q1VZ1GJMJM`
**Agent:** uwf-claude-code | **Time:** 2026-05-24 05:47:12

<prompt>
You are a planning agent...
</prompt>

<output>
---
plan: CMWGHQKT58RY4
status: ready
---

# Analysis Complete
...
</output>

理由

  1. agent 可读性好 — 简洁、自解释
  2. 不破坏 heading 层级 — agent 输出的 # 标题被 XML tag 隔离,不与外层冲突
  3. 前端可扩展 — react-markdown 等组件支持 components={{ prompt: ..., output: ... }} 自定义渲染
  4. CommonMark 兼容 — raw HTML tag 在 CommonMark 中是合法语法

实现

  • 修改 formatThreadReadMarkdown 中的 content 输出,用 <prompt><output> 包裹
  • step-details 展开 CAS 内容时同样用 XML tag
  • 移除原来的 ### Content / ### Prompt heading

— 小橘 🍊(NEKO Team)

## 设计方案:XML Tag 隔离 放弃 heading demotion 方案(需正确解析 markdown、h6 上限问题)。改用自定义 XML tag 包裹 prompt 和 output: ```markdown ## Step 1: planner `ER9Q1VZ1GJMJM` **Agent:** uwf-claude-code | **Time:** 2026-05-24 05:47:12 <prompt> You are a planning agent... </prompt> <output> --- plan: CMWGHQKT58RY4 status: ready --- # Analysis Complete ... </output> ``` ### 理由 1. **agent 可读性好** — 简洁、自解释 2. **不破坏 heading 层级** — agent 输出的 `#` 标题被 XML tag 隔离,不与外层冲突 3. **前端可扩展** — react-markdown 等组件支持 `components={{ prompt: ..., output: ... }}` 自定义渲染 4. **CommonMark 兼容** — raw HTML tag 在 CommonMark 中是合法语法 ### 实现 - 修改 `formatThreadReadMarkdown` 中的 content 输出,用 `<prompt>` 和 `<output>` 包裹 - `step-details` 展开 CAS 内容时同样用 XML tag - 移除原来的 `### Content` / `### Prompt` heading — 小橘 🍊(NEKO Team)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#459