Skip to content

fix(channels): use markdownToTelegramHtml for Telegram text formatting#1978

Merged
piorpua merged 2 commits intomainfrom
fix/issue-1214
Mar 31, 2026
Merged

fix(channels): use markdownToTelegramHtml for Telegram text formatting#1978
piorpua merged 2 commits intomainfrom
fix/issue-1214

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • formatTextForPlatform() in ActionExecutor.ts had no Telegram-specific branch, so it fell through to escapeHtml() which stripped all Markdown formatting (bold, italic, code, links)
  • Added a telegram case that calls the existing markdownToTelegramHtml() function from TelegramAdapter.ts
  • Fixed regex ordering in markdownToTelegramHtml(): code blocks are now processed before inline code to prevent partial backtick matches

Related Issues

Closes #1214

Test Plan

  • Unit tests for escapeHtml and markdownToTelegramHtml (10 tests)
  • Type check passes
  • Lint and format pass

formatTextForPlatform() had no Telegram-specific branch, falling through
to escapeHtml() which stripped all Markdown formatting. Added a telegram
case that calls the existing markdownToTelegramHtml() function.

Also fixed regex ordering in markdownToTelegramHtml() so code blocks are
processed before inline code to prevent partial matches.
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

Code Review:fix(channels): use markdownToTelegramHtml for Telegram text formatting (#1978)

变更概述

本 PR 名义上修复 Telegram 消息格式化问题(formatTextForPlatform 增加 telegram 分支、修正 markdownToTelegramHtml 正则顺序),但实际包含大量不相关改动(39 个文件):新增 thinking 消息系统(含 UI 组件、IPC 消息类型、DB 持久化)、CodeBlock 折叠/展开优化、MarkdownView 组件 memo 化、auto-scroll 改进、工具摘要增强、adapter 序列化守卫、ElectronPlatformServices 日志路径降级等。


方案评估

结论⚠️ 方案有缺陷

Telegram 格式化修复本身正确且合理——增加 telegram 分支调用 markdownToTelegramHtml,以及将 code block 正则移到 inline code 之前都是正确的修改。但本 PR 同时移除了 filterThinkTagsFromMessage(从 content 消息中剥离 <think> 标签的逻辑),改为通过 thought 事件转换为 thinking 消息。如果有模型直接在 content 消息中嵌入 <think> 标签(如 MiniMax 等),这些标签将泄漏到 UI。新增的 extractAndStripThinkTags 工具函数似乎是为此场景准备的,但本 PR 并未使用。


问题清单

🟡 MEDIUM — 移除 think tag 过滤可能导致 <think> 标签泄漏到 UI

文件src/process/task/AcpAgentManager.ts,第 447-448 行

问题代码

const emitStart = Date.now();
ipcBridge.acpConversation.responseStream.emit(message as IResponseMessage);

问题说明:旧代码通过 filterThinkTagsFromMessage 在发送到 UI 前从 content 类型消息中剥离 <think>...</think> 标签。该方法已被移除,现在 content 消息直接发送。对于在响应中内嵌 <think> 标签的模型(如 MiniMax),标签内容会原样显示在聊天界面中。ThinkTagDetector.ts 中新增了 extractAndStripThinkTags 函数但本 PR 未使用,疑似遗漏。

修复建议:在 emit 前对 content 类型消息应用 extractAndStripThinkTags,将 thinking 部分路由到 thinking 消息,stripped 内容继续作为 content 发送:

if (message.type === 'content' && typeof message.data === 'string') {
  const { thinking, content: stripped } = extractAndStripThinkTags(message.data);
  if (thinking) {
    this.emitThinkingMessage(thinking, 'thinking');
  }
  if (stripped !== message.data) {
    message = { ...message, data: stripped };
  }
}
ipcBridge.acpConversation.responseStream.emit(message as IResponseMessage);

🟡 MEDIUM — 残留的 JSDoc 片段

文件src/process/task/AcpAgentManager.ts,第 815-817 行

问题代码

   * @param message - The streaming message to filter
   * @returns Message with think tags removed from content
   */
  /**
   * Emit a thinking message to the UI stream.

问题说明:旧方法 filterThinkTagsFromMessage 的 JSDoc 尾部(@param message@returns)残留在新方法 emitThinkingMessage 的 JSDoc 前面。应清理。

修复建议:删除 815-817 行的残留注释。


🔵 LOW — thought 状态在 useAcpMessage 中已不再被消费

文件src/renderer/pages/conversation/platforms/acp/useAcpMessage.ts

问题说明thoughtsetThought 状态仍被声明和维护(在 finishresetState 中调用 setThought),thought 也仍在返回值中,但 AcpSendBox.tsx 不再解构使用它。ThoughtDisplay 也不再接收 thought prop。这是死代码。

修复建议:移除 thoughtsetThoughtthrottledSetThought 相关代码,同时从 UseAcpMessageReturn 类型中移除 thought 字段。


🔵 LOW — extractAndStripThinkTags 新增但未使用

文件src/process/task/ThinkTagDetector.ts,第 66-108 行

问题说明:新增了 extractAndStripThinkTags 函数并编写了测试,但在整个 PR 的变更文件中没有被 import 或调用。如果是为上述 MEDIUM 问题准备的修复,应在本 PR 中集成使用。


汇总

# 严重级别 文件 问题
1 🟡 MEDIUM AcpAgentManager.ts:447 移除 think tag 过滤,<think> 标签可能泄漏到 UI
2 🟡 MEDIUM AcpAgentManager.ts:815 残留的旧方法 JSDoc 片段
3 🔵 LOW useAcpMessage.ts thought 状态已成死代码
4 🔵 LOW ThinkTagDetector.ts:66 extractAndStripThinkTags 新增但未使用

结论

⚠️ 有条件批准 — 存在 2 个 MEDIUM 问题:think tag 过滤移除可能导致部分模型的内部推理内容泄漏到 UI(功能回退),以及残留的 JSDoc 注释。修复后可合并。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

CONCLUSION: CONDITIONAL
IS_CRITICAL_PATH: false
PR_NUMBER: 1978

@piorpua piorpua added bot:ready-to-fix CONDITIONAL review done, waiting for bot fix bot:fixing Fix in progress (mutex) and removed bot:reviewing Review in progress (mutex) bot:ready-to-fix CONDITIONAL review done, waiting for bot fix labels Mar 31, 2026
- Apply extractAndStripThinkTags before emitting content messages to UI,
  preventing <think> tag leakage from models like MiniMax
- Remove residual JSDoc from deleted filterThinkTagsFromMessage method

Review follow-up for #1978
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 31, 2026

PR Fix 验证报告

原始 PR: #1978
修复方式: 直接推送到 fix/issue-1214

# 严重级别 文件 问题 修复方式 状态
1 🟡 MEDIUM AcpAgentManager.ts:447 移除 think tag 过滤导致 <think> 标签泄漏到 UI 在 emit 前调用 extractAndStripThinkTags,thinking 部分路由到 thinking 消息,stripped 内容继续作为 content 发送 ✅ 已修复
2 🟡 MEDIUM AcpAgentManager.ts:815 残留的旧方法 filterThinkTagsFromMessage JSDoc 片段 删除残留的 6 行 JSDoc 注释 ✅ 已修复

总结: ✅ 已修复 2 个 | ❌ 未能修复 0 个

🔵 LOW 级别问题已跳过(不阻塞合并,修复优先级低)。

@piorpua piorpua enabled auto-merge (squash) March 31, 2026 06:28
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:fixing Fix in progress (mutex) labels Mar 31, 2026
@piorpua piorpua merged commit 3c7469b into main Mar 31, 2026
14 of 17 checks passed
@piorpua piorpua deleted the fix/issue-1214 branch March 31, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram bot does not render Markdown (shows raw asterisks)

2 participants