Skip to content

feat(im): render complete pretty chat transcripts - #2313

Open
WEIFENG2333 wants to merge 4 commits into
larksuite:mainfrom
WEIFENG2333:codex/im-pretty-conversation
Open

feat(im): render complete pretty chat transcripts#2313
WEIFENG2333 wants to merge 4 commits into
larksuite:mainfrom
WEIFENG2333:codex/im-pretty-conversation

Conversation

@WEIFENG2333

@WEIFENG2333 WEIFENG2333 commented Aug 12, 2026

Copy link
Copy Markdown

背景

lark-cli im +chat-messages-list --format pretty 原本只用表格展示主消息摘要:正文最多保留 40 个字符,也不展示已经获取到的 thread_replies。但如果石头 raw json 模式,有超级超级大量的无关字段,格式非常非常非常 AI 不友好

改动前

以下示例中的姓名、正文、消息 ID 和分页信息均为虚构数据。

CONTENT                                   SENDER  TIME              TYPE
帮忙 review 一下 MR 1234?背景是登录回调偶发超...  小林     2026-08-11 21:37  post

1 message(s)
tip: use --format json to view full message content

从这个输出中只能看到一条截断摘要。完整背景、复现代码和话题里的 review 结论都丢失了。

改动后

pretty 改为按主消息组织的完整会话记录。每条正文只占一行,原始换行等控制字符使用 \n\r\t 转义:

2026-08-11 21:37 · 小林
> 帮忙 review 一下 MR 1234?\n背景:登录回调偶发超时,复现步骤如下:\n1. 打开登录页\n2. 连续刷新两次\n\n```go\nif err != nil {\n    return retry(err)\n}\n```

message: om_example_root · thread: omt_example_thread

  ↳ 21:42 · 小周
    > 看过了,建议把重试放到调用方,并补一个超时测试。
    表情:THUMBSUP×2、DONE×1

  ↳ 21:48 · 小林
    > 已撤回

────────────────────────

1 messages · 2 thread replies · has_more: true · page_token: next_page_token

现在可以直接读到完整正文和话题回复;根消息仍保留继续读取话题或翻页所需的信息,回复本身不再重复展示 message_id

具体改动

  • 按主消息分组,将 thread_replies 缩进展示在对应根消息下;
  • 根据 message_id 过滤线程接口重复返回的根消息和重复回复;
  • 正文不再截断,但每条消息只占一行;反斜杠、换行、回车和 Tab 分别转义为 \\\n\r\t
  • 主消息保留 message_idthread_id 和普通回复的 reply_to;话题回复只显示时间、发送者、正文和表情;
  • 汇总表情,例如 表情:THUMBSUP×2、DONE×1
  • 撤回消息显示为 已撤回
  • 只有特殊内容无法正常渲染时才回退显示消息类型,不默认展示 text / post
  • 显示话题未完整展开或获取失败的状态;
  • 页尾显示主消息数、可见话题回复数、has_morepage_token
  • pretty 隐藏 tenant、position、AppLink、国际化发送者字段和编辑状态等 OpenAPI 传输噪音。

兼容性

  • 只改变 --format pretty 的阅读体验;
  • JSON、NDJSON、CSV 和 table 的输出结构保持不变;
  • pretty 不保证机器可逆解析,程序处理仍应使用 JSON。

验证

  • make unit-test
  • make vet
  • make fmt-check
  • QUALITY_GATE_CHANGED_FROM=origin/main make quality-gate
  • go mod tidygo.mod / go.sum 无变化
  • 使用本机已配置的 Bot 凭证做真实只读验证:10 条主消息展开为 25 条可见回复;线程接口重复返回的 7 条根消息全部被过滤;35 条正文全部只占一行;其中 2 条真实多行正文转义后与 JSON 完整匹配;回复 message_id 命中数为 0;根消息 ID 和分页状态仍保留

真实验证只记录脱敏统计,不包含群名、成员姓名、消息正文、消息 ID、群 ID 或分页 token。

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added a --format pretty option for chat message lists.
    • Displays readable conversation transcripts with complete content, timestamps, senders, reactions, quoted messages, and thread replies.
    • Handles recalled, empty, unsupported, and malformed messages with clear fallback output.
    • Includes pagination notices and transcript summaries where applicable.
  • Documentation

    • Updated usage guidance and examples for human-readable transcripts and machine-readable JSON output.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 78e8eb36-a059-4c37-b3ea-22fccc368ea2

📥 Commits

Reviewing files that changed from the base of the PR and between c509620 and 722dcef.

📒 Files selected for processing (4)
  • affordance/im.md
  • shortcuts/im/im_chat_messages_pretty.go
  • shortcuts/im/im_chat_messages_pretty_test.go
  • skills/lark-im/references/lark-im-chat-messages-list.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • skills/lark-im/references/lark-im-chat-messages-list.md
  • affordance/im.md
  • shortcuts/im/im_chat_messages_pretty_test.go
  • shortcuts/im/im_chat_messages_pretty.go

📝 Walkthrough

Walkthrough

The +chat-messages-list command now supports pretty conversation transcripts with thread replies, metadata, reactions, pagination notices, and fallback handling. Documentation and audited examples recommend --format pretty for readable conversations.

Changes

IM pretty transcript

Layer / File(s) Summary
Pretty transcript renderer
shortcuts/im/im_chat_messages_pretty.go
Adds transcript rendering for messages, thread replies, metadata, reactions, fallback content, escaping, and pagination notices.
Command wiring and validation
shortcuts/im/im_chat_messages_list.go, shortcuts/im/im_chat_messages_pretty_test.go
Routes --format pretty through the new renderer and adds renderer and command execution tests.
Usage guidance and audited examples
affordance/im.md, internal/affordance/im_source_test.go, skills/lark-im/references/lark-im-chat-messages-list.md
Updates examples and guidance for complete conversation transcripts and JSON processing.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ImChatMessageListExecute
  participant renderChatMessagesPretty
  participant ThreadReplies
  participant TranscriptOutput
  ImChatMessageListExecute->>renderChatMessagesPretty: pass projected chat messages
  renderChatMessagesPretty->>ThreadReplies: format loaded and unexpanded replies
  renderChatMessagesPretty->>TranscriptOutput: write transcript and pagination footer
Loading

Possibly related PRs

Suggested labels: feature

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: rendering complete pretty chat transcripts.
Description check ✅ Passed The description explains the motivation, changes, compatibility, validation, and related issues, although it uses different section headings than the template.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added domain/im PR touches the im domain size/L Large or sensitive change across domains or core paths labels Aug 12, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added size/M Single-domain feat or fix with limited business impact and removed size/L Large or sensitive change across domains or core paths labels Aug 12, 2026
@WEIFENG2333
WEIFENG2333 marked this pull request as ready for review August 12, 2026 10:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@affordance/im.md`:
- Around line 62-63: Update the `--format pretty` guidance in `affordance/im.md`
lines 62-63 and the corresponding chat-message listing guidance in
`skills/lark-im/references/lark-im-chat-messages-list.md` line 155 to describe
bounded output, not complete transcripts or conversations. State that users must
continue with `--page-token` or `--page-all` for additional outer messages, and
use `+threads-messages-list` when all thread replies are needed.

In `@shortcuts/im/im_chat_messages_pretty.go`:
- Around line 28-39: De-duplicate non-empty root message IDs before the
rendering loop, preserving a single occurrence while retaining messages without
an ID. Update the loop and footer in the surrounding chat-message rendering
function to use the filtered slice, while continuing to accumulate reply counts
and pagination data normally. Add a nearby regression test containing the same
root message map twice and assert it renders once with the corrected footer
count.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e6b71b8e-e84f-462f-b701-41f340e99968

📥 Commits

Reviewing files that changed from the base of the PR and between fd97039 and c509620.

📒 Files selected for processing (6)
  • affordance/im.md
  • internal/affordance/im_source_test.go
  • shortcuts/im/im_chat_messages_list.go
  • shortcuts/im/im_chat_messages_pretty.go
  • shortcuts/im/im_chat_messages_pretty_test.go
  • skills/lark-im/references/lark-im-chat-messages-list.md

Comment thread affordance/im.md Outdated
Comment thread shortcuts/im/im_chat_messages_pretty.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants