Skip to content

fix: 统一结果卡片样式 - 移除旧的 buildResultCard - #236

Merged
lishuceo merged 3 commits into
mainfrom
feat/unify-result-card
May 17, 2026
Merged

fix: 统一结果卡片样式 - 移除旧的 buildResultCard#236
lishuceo merged 3 commits into
mainfrom
feat/unify-result-card

Conversation

@lishuceo

Copy link
Copy Markdown
Owner

Summary

  • 土豆儿等 direct-mode agent 完成时走的是旧的 buildResultCard,渲染出硬编码的 "🤖 Coding Agent" 标题,并且和 /t 流程的 ensureThread 占位卡片各发一张,导致重复
  • 统一改为使用 buildCombinedProgressCard 在占位卡片上原地 updateCard,去掉硬编码 header
  • 删除已无引用的 buildResultCard / buildSimpleResultCard 及其工具函数 formatOutputAsMarkdownhostname 引入

Test plan

  • npm run typecheck
  • npx vitest run 受影响的 4 个测试文件 121/121 通过
    • src/feishu/__tests__/message-builder.test.ts
    • src/feishu/__tests__/event-handler.test.ts
    • src/feishu/__tests__/chat-history-fork.test.ts
    • src/__tests__/bot-identity-context.test.ts
  • 部署后实际在飞书群中触发 direct-mode (土豆儿) 与 /t 流程,确认占位卡片原地更新且无 "Coding Agent" 标题

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Claude finished @lishuceo's task in 3m 10s —— View job


Code Review — ⚠️ Issues Found

  • Check for previous review comments (none)
  • Review changed files
  • Verify correctness across module boundaries
  • Post review feedback

总体评价

PR 思路清晰且方向正确:通过移除硬编码 🤖 Coding Agent header 的 buildResultCard / buildSimpleResultCard,统一改用 buildCombinedProgressCard,让 direct-mode 和 /t 流程的卡片样式一致,避免占位卡 + 结果卡重复。代码删除量大于新增(-267/+53),是健康的清理重构。测试 mock 同步更新,签名匹配。

发现的问题

🟡 sendDirectReply 失败分支会显示矛盾的 "⏳ 正在处理..." + "❌ 执行失败" (confidence 85) — 见 inline comment

progressCardMsgId 分支在 result.success=false 时把 text 置为 ''toolCalls 置为 [],触发 buildCombinedProgressCard 的空态占位(message-builder.ts:683-689),导致用户看到 "正在处理" 与 "执行失败" 同时出现,且会丢弃 result.output 中可能存在的 partial 输出(与 sendResultCard 路径不一致)。

通过检查项

  • ✅ Imports 清理(hostnameformatOutputAsMarkdown)正确,无残留引用
  • ✅ 4 个测试文件 mock 签名与新调用一致
  • sendResultCard_prompt 重命名符合 TypeScript 未用参数约定(callers 传值无副作用)
  • ✅ ESM .js 后缀、singleton 用法符合 CLAUDE.md 约定
  • ✅ PR body 中 npx vitest run 受影响文件 121/121 通过
    | Branch: feat/unify-result-card

Comment thread src/feishu/event-handler.ts
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Claude finished @lishuceo's task in 2m 38s —— View job


Code Review — ⚠️ Issues Found

  • Check previous review comments and resolution status
  • Read changed files and understand current state
  • Verify fix for progressCardMsgId failure-branch issue
  • Look for any new issues introduced in latest commit
  • Post review feedback

总体评价

第二个 commit 27b72ae 完成了 review 的一部分(success: true 修正 + 死参数清理),但主要的 bug 仍未修复——失败态下 '⏳ 正在处理...' 占位元素仍会与 ❌ 执行失败 状态栏同框显示。

问题

🟡 失败态卡片正文显示 "⏳ 正在处理..."(confidence 90,未修复)

新 commit 仅修改了 success 标志位,未触及失败分支的 text 赋值。当前 src/feishu/event-handler.ts:2994-2996 仍是:

const text = result.success
  ? (result.output || '_(无输出)_')
  : '';

调用 buildCombinedProgressCard('', [], 1, true, undefined, { success: false, error }) 时:

  • hasText=false + hasTools=falsemessage-builder.ts:684-689 仍 push ⏳ 正在处理...
  • 紧接着 push 错误块
  • 底部状态栏 push ❌ 执行失败

影响范围:该 bug 还波及 sendResultCard 的三个调用点(event-handler.ts:2414、2514、2586)——尤其是 line 2415 显式传入 output: '' 的"工作区准备失败"兜底分支,必然命中。

建议修法(在 buildCombinedProgressCard 内统一防御,所有调用点受益):

   // --- 空状态 ---
-  if (!hasText && !hasTools) {
+  if (!hasText && !hasTools && !(completed && result)) {
     elements.push({
       tag: 'div',
       text: { tag: 'lark_md', content: '⏳ 正在处理...' },
     });
   }

完成态下若卡片正文为空,让 footer 的 ❌ 执行失败 + 错误块独立承担状态展示,不再矛盾。

详细回复见 inline thread

Fix this →

通过检查项

  • ✅ Commit 27b72ae 的两项改动(success: result.success 跟随实际结果 / 删除 _prompt 死参数)正确无副作用
  • ✅ 4 个测试文件 mock 签名同步更新
  • ✅ 删除的 buildResultCard / buildSimpleResultCard / formatOutputAsMarkdown / hostname 引入无残留引用
  • ✅ ESM .js 后缀、singleton 用法符合 CLAUDE.md 约定

Branch: feat/unify-result-card |

lishuceo and others added 2 commits May 15, 2026 13:33
土豆儿等 direct-mode agent 完成时仍走 buildResultCard,导致出现
"🤖 Coding Agent" 旧标题且与占位卡片重复。改为统一使用
buildCombinedProgressCard 原地更新,删除旧的 buildResultCard /
buildSimpleResultCard。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- buildCombinedProgressCard 长文本分支:success 跟随 result.success,避免依赖前置 return 的耦合
- sendResultCard 删除已成死代码的 _prompt 参数及 3 个调用点的 prompt 实参

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lishuceo
lishuceo force-pushed the feat/unify-result-card branch from 27b72ae to a4d766a Compare May 15, 2026 05:33
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Claude finished @lishuceo's task in 1m 58s —— View job


Code Review — ⚠️ Issues Found

  • Check previous review comments and their resolution
  • Read changed files in latest commit
  • Verify if the failure-branch ⏳ 正在处理... bug is fixed
  • Post review feedback

总体评价

pull request synchronize 后扫了一遍最新 head(a4d766a),之前 review 提出的失败态 "⏳ 正在处理..." bug 仍未修复。本次 push 主要是已有 commit 的 SHA 变化(force-push 重写为 a4d766a),代码内容无新增有意义变更。

仍存在的问题

🟡 失败态卡片正文显示 ⏳ 正在处理...(confidence 90,未修复)

当前 src/feishu/event-handler.ts:2994-2996

const text = result.success
  ? (result.output || '_(无输出)_')
  : '';

src/feishu/message-builder.ts:683-689 仍是无防御的空态分支:

if (!hasText && !hasTools) {
  elements.push({ tag: 'div', text: { tag: 'lark_md', content: '⏳ 正在处理...' } });
}

失败 + 无 output 时(text=''toolCalls=[]completed=trueresult.success=false),用户会看到 ⏳ 正在处理... + 错误块 + ❌ 执行失败 三者同框,与 PR 初衷"避免遗留 '正在处理...'"矛盾。

影响范围:同样 bug 还波及 sendResultCard 的 3 个调用点:

  • event-handler.ts:2414(工作区准备失败兜底,显式传 output: ''必然命中
  • event-handler.ts:2514(restart 失败分支)
  • event-handler.ts:2586(主流程失败分支)

最干净的修法(在 buildCombinedProgressCard 内部一次性防御,所有调用点受益):

-  if (!hasText && !hasTools) {
+  if (!hasText && !hasTools && !(completed && result)) {
     elements.push({
       tag: 'div',
       text: { tag: 'lark_md', content: '⏳ 正在处理...' },
     });
   }

详细已 reply 到 inline thread

Fix this →

通过检查项

  • ✅ 删除 buildResultCard / buildSimpleResultCard / formatOutputAsMarkdown / hostname 引入无残留引用
  • ✅ Commit a4d766a 的两项改动(success: result.success / 移除死参 _prompt)正确无副作用
  • ✅ 4 个测试文件 mock 签名同步更新
  • ✅ ESM .js 后缀、singleton 用法符合 CLAUDE.md 约定
  • ✅ 本次 push 未引入新的回归问题
    | Branch: feat/unify-result-card

- buildCombinedProgressCard 空态占位增加 !(completed && result) 防御,
  完成态带 result 时不再渲染 "⏳ 正在处理..." 占位元素,避免与下方
  错误块/状态栏的 "❌ 执行失败" 矛盾。覆盖 sendDirectReply +
  sendResultCard 全部 4 个调用点。
- sendDirectReply 失败分支保留 partial output(执行器可能在
  timeout/budget 触发前已产出文本),与 sendResultCard 行为一致。
- 新增回归测试。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

Claude finished @lishuceo's task in 1m 34s —— View job


Code Review — ✅ Approved

  • Check previous review comments and resolution status
  • Read changed files in latest commit (adbfea0)
  • Verify fix for failure-branch ⏳ 正在处理... bug
  • Look for any new issues / regressions
  • Post review feedback

总体评价

Commit adbfea0 正确修复了之前 review 反复提出的失败态卡片矛盾 bug,采用了 inline thread 中建议的"在 buildCombinedProgressCard 内部一次性防御"方案,且额外保留了 partial output 与 sendResultCard 行为一致。1 previous issue fixed,无新回归。

已验证修复点

buildCombinedProgressCard 空态防御src/feishu/message-builder.ts:685

if (!hasText && !hasTools && !(completed && result)) {

完成态带 result 时跳过 ⏳ 正在处理... 占位,覆盖全部 4 个调用点:

  • sendDirectReplyprogressCardMsgId 路径(event-handler.ts:2998
  • sendResultCardevent-handler.ts:3086 → 被 2414/2514/2586 三处复用

sendDirectReply 失败分支保留 partial outputsrc/feishu/event-handler.ts:2995-2997

const text = result.success
  ? (result.output || '_(无输出)_')
  : (result.output || '');

sendResultCardsrc/feishu/event-handler.ts:3082 (lastTurn?.textContent ?? result.output ?? '') 的语义对齐 —— timeout/budget 触发前的部分输出不再丢弃。

回归测试src/feishu/__tests__/message-builder.test.ts:504-514

it('should NOT show "正在处理" placeholder on completed failure with no text/tools', ...

精准覆盖 text=''toolCalls=[]completed=truesuccess=false 的退化场景,验证占位不出现且错误信息照常展示。

通过检查项

  • ✅ 修复方案对全部 4 个调用点都生效,未遗漏
  • ✅ 失败 + 仅 error 场景下:footer ❌ 执行失败 + 错误块独立承担状态展示,不再矛盾
  • ✅ 失败 + 有 partial output 场景下:output 作为正文显示,错误块在下方补充
  • ✅ 成功 + 无 output 仍然显示 _(无输出)_(沿用旧行为)
  • ✅ 删除的 buildResultCard / buildSimpleResultCard / formatOutputAsMarkdown / hostname 无残留引用
  • ✅ ESM .js 后缀、singleton 用法符合 CLAUDE.md 约定
  • ✅ 之前提出的 3 条 inline 评论已 reply 标记 fixed,线程已 resolved

| Branch: feat/unify-result-card | |

@lishuceo
lishuceo merged commit 6be3198 into main May 17, 2026
6 checks passed
@lishuceo
lishuceo deleted the feat/unify-result-card branch May 17, 2026 01:06
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.

1 participant